db.getRole() in mongoDB

getRole(rolename, { showPrivileges?, showBuiltinRoles? }?)

This method returns the roles from which this role inherits privileges. Optionally, the method can also return all the role’s privileges.


Syntax:

db.getRole(roleName)


Example 1: When the role is present with the given name.

use admin

db.getRole( "myAdmin" )


MongoDB

db.getRole( "myAdmin" )

Output:

{
    "_id" : "admin.myAdmin",
    "role" : "myAdmin",
    "db" : "admin",
    "roles" : [
            {
                    "role" : "read",
                    "db" : "admin"
            }
    ],
    "inheritedRoles" : [
            {
                    "role" : "read",
                    "db" : "admin"
            }
    ],
    "isBuiltin" : false
}



Example 2: When the role is not present with the given name.

use admin

db.getRole( "newRole" )


MongoDB

db.getRole( "newRole" )

Output:

null


No comments:

Post a Comment