Spring boot鏈接3.03以上的mongodb 權限驗證問題

因爲3.0.3,mongodb加入了SCRAM-SHA-1校驗方式,須要第三方工具配合進行驗證,全部Spring boot鏈接MongoDB時會出現用戶認證失敗。mongodb

解決方法:服務器

> 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 }) 

刪除原來建立的已經使用了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'}]}) 

而後關閉服務器,開啓認證,重啓服務器!!spa

相關文章
相關標籤/搜索