MongoDB在mLab身份验证上失败
按照此处的步骤创建一个新的mLab帐户并创建一个数据库 http://docs.mlab .com/#create-sub .尝试使用mongo shell和mongoose Node.js模块连接到数据库,但在两种情况下都看到身份验证失败"错误.
Created a new mLab account and created a database as per the steps here http://docs.mlab.com/#create-sub . Trying to connect to the database using mongo shell and mongoose Node.js module but I see the 'Authentication Failed' errorin both cases.
在Mongo shell中,命令是,我已经仔细检查了凭据
In Mongo shell the command is, I have double checked the credentials
mongo ds012345.mlab.com:56789/dbname -u dbuser -p dbpassword
错误:
MongoError: authentication fail
at Function.MongoError.create (E:\Gatsby\notmongoose\node_modules\mongodb-core\lib\error.js:31:11)
使用猫鼬
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);
});
});
错误:: MongoConnect错误MongoError:身份验证失败
Error:: MongoConnect Error MongoError:authentication fail
在mLab控制台上还有其他需要做的事情吗?或者我可能做错了或遗漏的其他事情?
Is there anything else that needs to be done on the mLab console or anything else that I might be doing wrong or missing?
您需要在mLab帐户中为数据库创建一个新用户.然后在mlab帐户中使用该创建的用户登录.然后单击特定的数据库并单击用户".标签,请参见下图:
You needs to create a new user for the database in mLab account.and login with that created user on mlab account.then click on specific database and click on users tab, see in image below:
现在填写表格并为数据库创建用户.见下图:
Now fill the form and create user for database. See in image below :
现在,在代码中使用以下字符串进行连接:
Now, in the code use the following string for connection:
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:'));