本文介绍了MongoError:身份验证失败的猫鼬连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以通过终端连接到DB,但是使用猫鼬和gulp会出现此错误。
mongoose / node_modules / mongodb / lib / mongodb / connection / base.js:246
MongoError:验证失败
I can connect to the DB through terminal, but getting this error using mongoose and gulp.mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246MongoError: auth failed
我的连接字符串是:
mongodb://usr:psw@localhost:27017/dbname
有什么想法吗?
推荐答案
我在 for Windows 7
安装时,我的密码是123456
I installed MEAN at https://bitnami.com/stack/mean for windows 7When install I make password is 123456
语法make connect to mongodb with mongoose
Syntax make connect to mongodb with mongoose
mongoose.connect("mongodb://[usr]:[pwd]@localhost:[port]/[db]",{auth:{authdb:"admin"}});
如果没有
{auth:{authdb:"admin"}}
您会收到错误消息消息 MongoError:身份验证失败
You will get error message "MongoError: auth failed"
示例: mongo-test / app.js
Example: mongo-test/app.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://root:123456@localhost/test',{auth:{authdb:"admin"}});
mongoose.set('debug', true); // turn on debug
这篇关于MongoError:身份验证失败的猫鼬连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!