mongodb创建用户创建库分配权限

use unionserver

db.createUser({ user: "rshy",pwd: "root1234@......",customData:{name:"root"},roles:[{ role: "userAdminAnyDatabase",db: "admin" }]})


db.grantRolesToUser("rshy", [ { role:"dbOwner", db:"fanwen"} ]) ;

db.grantRolesToUser("admin", [ { role:"dbOwner", db:"fanwen"} ]) ;


show users

use zhuna
use admin
db.grantRolesToUser("rshy", [ { role:"dbOwner", db:"zhuna"} ]) ;

db.grantRolesToUser("admin", [ { role:"dbOwner", db:"zhuna"} ]) ;

db.zhuna.insert({"name":""})

use zhuna_test
use admin
db.grantRolesToUser("rshy", [ { role:"dbOwner", db:"zhuna_test"} ]) ;

db.grantRolesToUser("admin", [ { role:"dbOwner", db:"zhuna_test"} ]) ;
db.zhuna_test.insert({"name":""})

use liuxue
use liuxue
use admin
db.grantRolesToUser("rshy", [ { role:"dbOwner", db:"liuxue"} ]) ;

db.grantRolesToUser("admin", [ { role:"dbOwner", db:"liuxue"} ]) ;
db.liuxue.insert({"name":""})

use liuxue_test
use admin
db.grantRolesToUser("rshy", [ { role:"dbOwner", db:"liuxue_test"} ]) ;

db.grantRolesToUser("admin", [ { role:"dbOwner", db:"liuxue_test"} ]) ;
db.liuxue_test.insert({"name":""})

 

mongodb创建用户创建库分配权限

上一篇:网页加载大量图片,如何提高加载速度


下一篇:JsonConvert After parsing a value an unexpected character was encountered