如何创建一个角色
建立一个用户角色使用createRole这个命令。每一个角色可以通过privileges授予一些系统特权,通过roles来授予一些数据库管理权限。writeConcern参数是保障写操作的可靠性。
use admin
db.createRole( { role: "myClusterwideAdmin", privileges: [ { resource: { cluster: true }, actions: [ "addShard" ] }, { resource: { db: "config", collection: "" }, actions: [ "find", "update", "insert" ] }, { resource: { db: "users", collection: "usersCollection" }, actions: [ "update" ] }, { resource: { db: "", collection: "" }, actions: [ "find" ] } ], roles: [ { role: "read", db: "admin" } ], writeConcern: { w: "majority" , wtimeout: 5000 } } ) )