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.
use sDatabase
first ? – feiiiiii20.345.145.12
is not a valid IP address. Something looks bent. – jww