MongoDB error during mLab authentication

Created a new mLab account and created the database according to the steps here http://docs.mlab.com/#create-sub . Trying to connect to the database using the mongo shell and mongoose Node.js, but I see an "Authentication Error" error in both cases.

There is a command in the Mongo shell, I double-checked the credentials

mongo ds012345.mlab.com:56789/dbname -u dbuser -p dbpassword

Error:

MongoError: authentication fail
at Function.MongoError.create (E:\Gatsby\notmongoose\node_modules\mongodb-core\lib\error.js:31:11)

Using Mongoose

var mongoose = require('mongoose')
, Admin = mongoose.mongo.Admin;

var uri = '<correct mongo uri here>';

var connection = mongoose.createConnection(uri,
{    
User: '<uname>',
Password: '<pwd>'
});
connection.on('open', function() {

console.log('connection established!!!');

new Admin(connection.db).listDatabases(function(err, result) {
    console.log('listDatabases succeeded');
    console.log(err);
    console.log(result); 
});

});

Error :: MongoConnect Error MongoError: authentication failed

Is there anything else that needs to be done on the mLab console or something else that I might be doing wrong or missing?

+4
source share
4 answers

mLab. mlab. "", . : user tab and add new user

. . :

enter image description here

:

var mongoose = require('mongoose');

var mongoDB = "mongodb://<username>:<password>@ds241489.mlab.com:41489/<DB Name>";

mongoose.connect(mongoDB, {
    useMongoClient: true
});

var db = mongoose.connection;

db.on('error', console.error.bind(console, 'MongoDB connection error:'));
+2

, mLab dbuser dbpassword.

- mLab .

mLab:

  • Databse
  • "".
  • add database user
+6
 var mongoose = require('mongoose');

 var mongoDB = "mongodb://user:123456@ds114989.mlab.com:13936/brary";

 mongoose.connect(mongoDB, {
    useMongoClient: true
 });

 var db = mongoose.connection;

 db.on('error', console.error.bind(console, 'MongoDB connection error:'));

: Mlab. Mlab. dbpassword 123456 , @, # u , 'dbuser': 'dbpassword'

+2

, , .

mLab mongo 3.4.9, , , Ubunty Xenial, 2.6.10.

This is an authentication error, even if the credentials used (database credentials, not mlab user credentials) are correct.

+2
source

Source: https://habr.com/ru/post/1683496/


All Articles