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();

 

posted @ 2024-01-22 17:33  slnngk  阅读(3)  评论(0编辑  收藏  举报