MongoDB基本操作

时间:2022-06-19 02:58:11

use sanhe


db.auth(‘sanhe‘,‘35DJqemUv72‘);

 

use admin


show dbs;

 

db.auth("root","[email protected]")

 

use admin


db.createUser({user: "root",pwd: "[email protected]",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})


./mongo --auth

 

db.auth("myUserAdmin", "abc123")
> db.grantRolesToUser("myUserAdmin", [ { role: "read", db: "admin" } ])