0
votes

I know this question is similar to this questions:

UserNotFound: Could not find user admin@automation

PyMongo - UserNotFound: Could not find user authenticated@admin

, but the answers coudln't help me and I'm very desperate now :(

My backend exception:

SCRAM-SHA-1 authentication failed for nodejs on sDatabase from client 20.345.145.12 ; UserNotFound: Could not find user nodejs@sDatabase

Mongo DB Version: 3.2.20

My frontend exception:

MongoError: Authentication failed.

NodeJS version: 8.9.4

NodeJS mongodb dependency version: ~3.0.10

My user:

> db.getUsers()
[
        {
                "_id" : "sDatabase.nodejs",
                "user" : "nodejs",
                "db" : "sDatabase",
                "roles" : [
                        {
                                "role" : "readWrite",
                                "db" : "sDatabase"
                        }
                ]
        }
]
>

My nodeJS code [which works with other mongoDB databases]:

var MongoClient = require('mongodb').MongoClient;

var pwd = "1234", //also tried with encodeURIComponent
    username = "nodejs",
    host = "1234.567.898.765",
    database = "sDatabase";

var url = "mongodb://" + username + ":" + pwd + "@" + host + ":27017/" + database; //also tried: ?authMechanism=SCRAM-SHA-1 //?authSource=sDatabase&w=1

MongoClient.connect(url, function(err, db) {
    if (err) throw err;
    console.log("Database created!");
    db.close();
});

Thanks a lot for every answer and comment and helpful letter.

1
well the user nodejs doesn't exist , you need to create itfeiiiiii
I thought I created it because when I write db.getUsers () at the Database he comes.Freddy C.
did you do use sDatabase first ?feiiiiii
yes. :/ . . . .Freddy C.
20.345.145.12 is not a valid IP address. Something looks bent.jww

1 Answers

0
votes

I have found the solution: I added "dbAdmin" to rules and now it works:

How I created my working user:

db.createUser({user: "nodejs", pwd: "1234", roles: ["readWrite", "dbAdmin"]});