mongodb3.0没有admin数据库了,怎么添加超级管理员

2025-03-23 14:31:33
推荐回答(1个)
回答1:

mongodb3.0添加超级管理员使用使用db.createUser()方法
方法签名:db.createUser(user, writeConcern)
英文解释:Creates a new user for the database where the method runs. db.createUser() returns a duplicate user error if the user already exists on the database.
参考代码:

use products
db.createUser( { "user" : "accountAdmin01",
"pwd": "cleartext password",
"customData" : { employeeId: 12345 },
"roles" : [ { role: "clusterAdmin", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
"readWrite"
] },
{ w: "majority" , wtimeout: 5000 } )