標籤:
首先先曬一下log 日誌錯誤資訊
2016-07-13T22:19:43.667+0800 I ACCESS [conn4] authenticate db: finddemo { authenticate: 1, nonce: "xxx", user: "user1", key: "xxx" }2016-07-13T22:19:43.668+0800 I ACCESS [conn4] Failed to authenticate [email protected]ddemo with mechanism MONGODB-CR: AuthenticationFailed: UserNotFound: Could not find user [email protected]2016-07-13T22:20:12.555+0800 I ACCESS [conn2] SCRAM-SHA-1 authentication failed for user1 on finddemo from client 127.0.0.1 ; UserNotFound: Could not find user [email protected]2016-07-13T22:20:17.127+0800 I NETWORK [initandlisten] connection accepted from 127.0.0.1:56103 #5 (4 connections now open)2016-07-13T22:20:17.127+0800 I ACCESS [conn5] authenticate db: admin { authenticate: 1, nonce: "xxx", user: "root", key: "xxx" }2016-07-13T22:20:17.146+0800 I NETWORK [initandlisten] connection accepted from 127.0.0.1:56104 #6 (5 connections now open)2016-07-13T22:20:17.146+0800 I ACCESS [conn6] authenticate db: admin { authenticate: 1, nonce: "xxx", user: "root", key: "xxx" }
著重看一下 這個報錯資訊,
SCRAM-SHA-1 authentication failed for user1 on finddemo
這是什麼鳥?
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 })
下面是擷取到的使用者的相關資訊
{ "_id" : "admin.root", "user" : "root", "db" : "admin", "credentials" : { "MONGODB-CR" : "97a156792bd180dc82cec9a56d838991" }, "roles" : [ { "role" : "__system", "db" : "admin" } ] }{ "_id" : "finddemo.finddemo", "user" : "finddemo", "db" : "finddemo", "credentials" : { "MONGODB-CR" : "4b8dce39de95d553473c1998f43aa165" }, "roles" : [ { "role" : "dbOwner", "db" : "finddemo" } ] }
重新串連,成功。
可以查看一下連結介紹:
https://docs.mongodb.com/master/release-notes/3.0-scram/
還有國外友人的回答:(越來越鄙視百度黨)
http://stackoverflow.com/questions/29006887/mongodb-cr-authentication-failed
mongodb 非 admin 庫 認證登陸失敗 原因(百度好多都 是渣)db.addUser() 請走開。