大家好,请教下,当Mongodb使用_auth参数启动后,Mongoose应该怎么连接才行?
看了Mongoose官网文档,尝试了以下连接方法:
1、
mongoose.connect("mongodb://admin:111111@localhost/root");
2、
var options = {
db: { native_parser: true },
server: { poolSize: 5 },
replset: { rs_name: 'myReplicaSetName' },
user: 'admin',
pass: '111111'
}
mongoose.connect("mongodb://localhost/root", options);
这两种方法的执行日志如下:
2015-09-13T09:57:04.990+0800 I ACCESS [conn17] Successfully authenticated as principal admin on root
然后就一直报错:
2015-09-13T09:57:04.995+0800 I ACCESS [conn19] Unauthorized not authorized on root to execute command { listIndexes: "sessions", cursor: {} }
尝试了将Mongodb的用户角色分别更改为:read readWrite dbAdmin userAdmin dbOwner 都报这个错,百度后无解,实在不知道如何解决了,求解!
我的Mongodb版本是3.0.6
Mongoose版本是4.1.5