MongoDB Tutorial

MongoDB: db.grantRolesToRole() method


The db.grantRolesToRole() method is used to specify roles from which a user-defined role inherits privileges.


db.grantRolesToRole( "<rolename>", [ <roles> ], { <writeConcern> } )


Name Description Required /
rolename The name of the role to which to grant sub roles. Required String
roles An array of roles from which to inherit. Required array
writeConcern The level of write concern for the modification. The writeConcern document takes the same fields as the getLastError command. Optional document

In the roles field, you can specify both built-in roles and user-defined role.

To specify a role that exists in the same database where db.grantRolesToRole() runs, you can either specify the role with the name of the role:


Or you can specify the role with a document, as in:

{ role: "<role>", db: "<database>" }

To specify a role that exists in a different database, specify the role with a document.

Example: MongoDB: db.grantRolesToRole() method

The following grantRolesToRole() operation updates the admin myroll1  role in the admin database to inherit the privileges of admin read role:

use admin
    [ "read" ],
    { w: "majority" , wtimeout: 5000 }

Retrieve the restaurants data from here


A role can inherit privileges from other roles in its database. A role created on the admin database can inherit privileges from roles in any database.

Previous: db.revokeRolesFromRole() method
Next: db.getRole() method

New Content: Composer: Dependency manager for PHP, R Programming

bedava porno