authenticate db: userdb { authenticate: 1, nonce: "xxx", user: "myuser", key: "xxx" }
2015-06-02T09:57:18.877+0800 I ACCESS [conn2] Failed to authenticate myuser@userdb with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
此1-5步骤针对是3.0.3以前版本已经ok,如果是3.0.3,mongodb加入了SCRAM-SHA-1校验方式,需要第三方工具配合进行验证,下面给出具体解决办法:
首先关闭认证,修改system.version文档里面的authSchema版本为3,初始安装时候应该是5,命令行如下:
> use admin
switched to db admin
> var schema = db.system.version.findOne({"_id" : "authSchema"})
> schema.currentVersion = 3
3
> db.system.version.save(schema)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
不过如果你现在开启认证,仍然会提示AuthenticationFailed MONGODB-CR credentials missing in the user document
原因是原来创建的用户已经使用了SCRAM-SHA-1认证方式
> use admin
switched to db admin
> db.system.users.find()
[...]
{ "_id" : "userdb.myuser", "user" : "myuser", "db" : "userdb", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "XXXXXXXXXXXXXXXXXXXXXXXX", "storedKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXX", "serverKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXX" } }, "roles" : [ { "role" : "dbOwner", "db" : "userdb" } ] }
解决方式就是删除刚刚创建的用户,重新重建即可:
> use userdb
switched to db userdb
> db.dropUser("myuser")
true
>db.createUser({user:'myuser',pwd:'123456',roles:[{role:'dbOwner',db:'userdb'}]})
然后关闭服务器,开启认证,重启服务器,用mongovue连接,一切OK