一 授权: 无认证登陆创建认证用户
1.use admin
2.创建访问某个数据库的用户
admin 数据库
use admin
db.createUser({user:"mongo",pwd:"mongo",roles:[{role:"root",db:"admin"}]})
db.createUser({user:"mongo",pwd:"mongo",roles:[{role:"readWrite",db:"nginxlogStatistic"}]})
3. exit 退出
二.认证
认证:认证登陆,保证认证用户访问
查询:
1.可以进入admin数据库
use admin;
show users;
db.auth("mongo","mongo")
show dbs;
use ngxlogStatistic
2.无法进入admin数据库,需要进行认证
use ngxlogStatistic
db.auth("mongo","mongo")
1.use admin
2.创建访问某个数据库的用户
admin 数据库
use admin
db.createUser({user:"mongo",pwd:"mongo",roles:[{role:"root",db:"admin"}]})
db.createUser({user:"mongo",pwd:"mongo",roles:[{role:"readWrite",db:"nginxlogStatistic"}]})
3. exit 退出
二.认证
认证:认证登陆,保证认证用户访问
查询:
1.可以进入admin数据库
use admin;
show users;
db.auth("mongo","mongo")
show dbs;
use ngxlogStatistic
2.无法进入admin数据库,需要进行认证
use ngxlogStatistic
db.auth("mongo","mongo")