MongoDB在mLab身份验证上失败

编程入门 行业动态 更新时间:2024-10-28 07:27:29
本文介绍了MongoDB在mLab身份验证上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

按照此处的步骤创建一个新的mLab帐户并创建一个数据库 docs.mlab /#create-sub .尝试使用mongo shell和mongoose Node.js模块连接到数据库,但在两种情况下都看到身份验证失败"错误.

Created a new mLab account and created a database as per the steps here docs.mlab/#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: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:41489/<DB Name>"; mongoose.connect(mongoDB, { useMongoClient: true }); var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:'));

更多推荐

MongoDB在mLab身份验证上失败

本文发布于:2023-10-13 00:39:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486317.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   MongoDB   mLab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!