官方文档说明:https://docs.mongodb.org/manual/tutorial/manage-users-and-roles
use admin
db.createUser({
user: "root",
pwd: "password",
roles: [ "root" ]
}
)
use xxx
db.createUser(
{
user: "username",
pwd: "password",
roles: [
{ role: "dbAdmin", db: "xxx" },
{ role: "dbOwner", db: "xxx" },
{ role: "read", db: "xxx" },
{ role: "readWrite", db: "xxx" },
{ role: "userAdmin", db: "xxx" }
]
}
)