新版本已取消addUser方法,改使用createUser方法
官方地址:https://docs.mongodb.com/manual/tutorial/create-users/
官方地址:https://docs.mongodb.com/manual/reference/command/createUser/#dbcmd.createUser
role权限:https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles
db.createUser( { user:‘user‘, pwd:‘passwd‘, roles:["dbAdminAnyDatabase","readWriteAnyDatabase"] } )
新版本默认使用SCRAM-SHA-1认证方式,连接mongo时会遇到这种报错:
错误:Failed to authenticate *@* with mechanism MONGODB-CR: AuthenticationFailed: MONGODB-CR credentials missing in the user document
> 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 })
无法登录的用户需要删除重新添加
时间: 2024-10-08 08:37:48