w3resource
MongoDB Tutorial

MongoDB: db.getRole() method

db.getRole()

The db.getRole() method is used to returns information for the specified role. Returns the roles from which this role inherits privileges.

Syntax:

db.getRole(rolename, showPrivileges)

The db.getRole() method takes the following arguments:

Parameters:

Name Description Required /
Optional
Type
rolename The name of the role. Required String
showPrivileges If true, returns the role’s privileges. Pass this argument as a document: {showPrivileges: true}. Optional document

Example : Get role information without privileges

The following operation returns role inheritance information for the role myroll1 defined on the admin database:

use admin
db.getRole( "myroll1" );

Output:

> db.getRole( "myroll1" );
{
        "role" : "myroll1",
        "db" : "admin",
        "isBuiltin" : false,
        "roles" : [
                {
                        "role" : "read",
                        "db" : "admin"
                }
        ],
        "inheritedRoles" : [
                {
                        "role" : "read",
                        "db" : "admin"
                }
        ]
}

Example : Get role information with privileges

The following operation returns role inheritance information and privileges for the role myroll1 defined on the admin database:

use admin
db.getRole( "myroll1", { showPrivileges: true } );

Output:

> db.getRole( "myroll1", { showPrivileges: true } );
{
        "role" : "myroll1",
        "db" : "admin",
        "isBuiltin" : false,
        "roles" : [
                {
                        "role" : "read",
                        "db" : "admin"
                }
        ],
        "inheritedRoles" : [
                {
                        "role" : "read",
                        "db" : "admin"
                }
        ],
        "privileges" : [
                {
                        "resource" : {
                                "db" : "config",
                                "collection" : " "
                        },
                        "actions" : [
                                "createCollection",
                                "createIndex",
                                "update"
                        ]
                }
        ],
        "inheritedPrivileges" : [
                {
                        "resource" : {
                                "db" : "config",
                                "collection" : " "
                        },
                        "actions" : [
                                "createCollection",
                                "createIndex",
                                "update"
                        ]
                },
                {
                        "resource" : {
                                "db" : "admin",
                                "collection" : ""
                        },
                        "actions" : [
                                "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                },
                {
                        "resource" : {
                                "db" : "admin",
                                "collection" : "system.indexes"
                        },
                        "actions" : [
                                "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                },
                {
                        "resource" : {
                                "db" : "admin",
                                "collection" : "system.js"
                        },
                        "actions" : [
                                "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                },
                {
                        "resource" : {
                                "db" : "admin",
                                "collection" : "system.namespaces"
                        },
                        "actions" : [
                                "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                }
        ]
}            "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                },
                {
                        "resource" : {
                                "db" : "admin",
                                "collection" : "system.namespaces"
                        },
                        "actions" : [
                                "collStats",
                                "dbHash",
                                "dbStats",
                                "find",
                                "killCursors",
                                "planCacheRead"
                        ]
                }
        ]
}

Retrieve the restaurants data from here

Previous: db.grantRolesToRole() method
Next: db.getRoles() method



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


bedava porno