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" } ])
原文:https://www.cnblogs.com/zplogo/p/12234910.html