添加用户:
db.createUser(
{
user: "admin",
pwd: "12345678",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
此命令创建的用户只有管理用户的权限,并没有操作数据库的权限。
查看用户 show user
创建用户,用户都跟着库走,创建的用户都是
use MutiQery
db.createUser(
{
user: "xxx",
pwd: "xxx123",
roles: [
{ role: "readWrite", db: "MutiQery" }
]
}
)
查看mongoDB的所有用户
use admin
db.system.users.find()
登陆验证
use MutiQery
db.auth("xxx","xxx123")
show collections