指定数据库时验证失败错误 [英] Auth failed error when specifying database

查看:69
本文介绍了指定数据库时验证失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Web应用程序连接到mongodb.但是,当我指定要连接的数据库时,会从mongo获得auth failed error.如果我未指定db,则连接成功.

I'm trying to connect to a mongodb from my web application. However, I get an auth failed error from mongo when I specify the database I want to connect to. If I do not specify the db, then to connection is successful.

我已经检查了拼写,并且是否使用mongo命令行show dbs

I have checked the spelling and if the database exits with the mongo command line show dbs

var dbURI = 'mongodb://root:pwd@localhost:27017/dbname';
mongoose.connect(dbURI, function(err) {
    if (err) throw err;
});

C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:245
        throw message;
              ^
MongoError: auth failed
    at Object.toError (C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\utils.js:114:11)
    at C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1130:31
    at C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1847:9
    at Server.Base._callHandler (C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:445:41)
    at C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:478:18
    at MongoReply.parseBody (C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
    at null.<anonymous> (C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:436:20)
    at emit (events.js:95:17)
    at null.<anonymous> (C:\Users\David\Documents\Bitbucket\productWebsite\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:201:13)
    at emit (events.js:98:17)

我正在使用Windows的Bitnami Mean Stack

I'm using Bitnami Mean stack for Windows

有人可以告诉我我忘记了什么吗?

Can someone tell me what I am forgetting?

推荐答案

您尝试向哪个数据库进行身份验证很重要.对创建用户的数据库进行身份验证.身份验证后,您可以切换到使用其他数据库.

It matters which database you try to authenticate to. Authenticate to the database where the user was created. You can switch to using other databases once authenticated.

这篇关于指定数据库时验证失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆