1. 创建用户
db.createUser(
{user:'<name>', #用户名
pwd:'<password>', #密码
customData:{<any information>}, #账户说明
roles:[{role:'<role1>',db:'<DataBase1>'},{role:'<role2>',db:'<DataBase2>'},...] #角色类型、涉及的数据库
})
角色类型:内建角色(read、readWrite、dbAdmin、userAdmin)
>db.createUser({user:'sssnow',pwd:'123456',roles:[{role:'readWrite',db:'testDB'}]})
Successfully added user: {
"user" : "test",
"roles" : [
{
"role" : "readWrite",
"db" : "testDB"
}
]
}
>
2. 更新用户信息
db.updateUser(
'<name>', #旧用户名
{user:'<name>', #新用户名
pwd:'<password>', #新密码
customData:{<any information>}, #账户说明
roles:[{role:'<role1>',db:'<DataBase1>'},{role:'<role2>',db:'<DataBase2>'},...] #角色类型、涉及的数据库
})
3. 删除用户
db.dropUser('<name>') #用户名
> use testDB
switched to db testDB
> db.dropUser('test')
true
>
4. 用户登陆
mongo IP:Port -u <name> -p <password>