throw message;
请问大家有遇到这种情况的吗?
2015-10-09T07:29:07.626753+00:00 app[web.1]: MongoError: auth failed
2015-10-09T07:29:07.626756+00:00 app[web.1]: at Object.toError (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)
2015-10-09T07:29:07.626758+00:00 app[web.1]: at /app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1156:31
2015-10-09T07:29:07.626759+00:00 app[web.1]: at /app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1890:9
2015-10-09T07:29:07.626760+00:00 app[web.1]: at Server.Base._callHandler (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
2015-10-09T07:29:07.626762+00:00 app[web.1]: at /app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
2015-10-09T07:29:07.626763+00:00 app[web.1]: at MongoReply.parseBody (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
2015-10-09T07:29:07.626766+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
2015-10-09T07:29:07.626765+00:00 app[web.1]: at emit (events.js:95:17)
2015-10-09T07:29:07.626764+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
2015-10-09T07:29:07.626767+00:00 app[web.1]: at emit (events.js:98:17)
2015-10-09T07:29:07.413053+00:00 app[web.1]: Listen the port 11221
2015-10-09T07:29:07.623584+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
2015-10-09T07:29:08.438433+00:00 heroku[web.1]: Process exited with status 8
mongodb 3.0的用户机制改变了,数据库账户需要重新设置一下。 1、开启 noauth=true,shell进入mongo,use admin,创建admin账户 3.0创建新用户方法 db.createUser,具体可查看官方文档 2、验证刚才创建的admin账户 db.auth(‘admin’,’pwd’) 3、use ‘你的数据库’ 4、db.createUser() 为你的数据库创建用户 5、重启mongodb,开启auth=true;
程序部分 mongoose.connect(url, {auth:{authdb:"你的数据库名字,不是admin数据库"}},
这样应该就可以了,我的升级3.0后这样设置就没问题了
mongodb设置大致如下: 1、use admin 2、db.createUser({ user:’root’, pwd:’xxxx’, rolses:[{ role: "readAnyDatabase", db: “admin” }] }) 3、db.auth(‘root’,’xxxx’) 4、use dataname 5、db.createUser({ user:’user1’, pwd:’xxxx’, rolses:[{ role: "readWirte", db: “dataname” }] }) 6、db.auth(‘user1’,’xxx’) 7、重启mongodb