大家好,請教下,當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
已解決,詳見 這篇帖子