mongodb账号管理
环境:
OS:Centos 7
DB:4.4.13
1.创建账号并授权(在admin下创建账号)
/usr/local/services/mongodb/bin/mongo localhost:28001
use admin
db.auth("root","root123");
db.createUser({user:'data_syn',pwd:'sdr123',roles:[{role:'read',db:'mgdb_message'}]});
##授权其他库1
db.runCommand(
{
grantRolesToUser: "data_syn",
roles:
[
{ role: "read", db: "growth_driven" }
]
}
)
##授权其他库2
db.runCommand(
{
grantRolesToUser: "data_syn",
roles:
[
{ role: "read", db: "growth_driven_test" }
]
}
)
2.查看账号情况
use admin;
db.system.users.find().pretty();