db.createUser({user:"user",pwd:"user",roles:["dbOwner"]})
-
如果 MongoDB 开启了权限模式,并且某一个数据库没有任何用户时,在不验证权限的情况下,可以创建一个用户,当继续创建第二个用户时,会返回错误,若想继续创建用户则必须登录。
2014-10-16T10:40:41.904+0800 Error: couldn't add user: not authorized on mydb to execute command { createUser: "test", pwd: "xxx", roles: [ { role: "dbOwner", db: "mydb" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0 } } at src/mongo/shell/db.js:1004 >
-
创建超级管理员