MongoDB基本操作
use sanhe
db.auth('sanhe','35DJqemUv72');
use admin
show dbs;
db.auth("root","1qaz@WSX")
use admin
db.createUser({user: "root",pwd: "1qaz@WSX",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
./mongo --auth
db.auth("myUserAdmin", "abc123")
> db.grantRolesToUser("myUserAdmin", [ { role: "read", db: "admin" } ])
// mongodb 副本集重新配置 > db.version(); 3.2.6 > conf=rs.conf() > conf.members[0].host="192.168.56.200:27017"; > rs.reconfig(rsconf,{"force":true}); // mongodb 副本集重新配置(可以在已经启用认证运行的MongoDB环境中执行) config = { _id : "shard1", members : [ {_id : 0, host : "172.31.62.225:27017", priority:2 }, {_id : 1, host : "172.31.62.224:27017", priority:1 }, {_id : 2, host : "172.31.62.226:27017", arbiterOnly:true } ] } rs.reconfig(config,{"force":true});