OPTIONS
翻译或纠错本页面

查看角色

概述

A role grants privileges to the users who are assigned the role. Each role is scoped to a particular database, but MongoDB stores all role information in the admin.system.roles collection in the admin database.

Prerequisites

To view a role’s information, you must be explicitly granted the role or must have the viewRole action on the role’s database.

Procedures

The following procedures use the rolesInfo command. You also can use the methods db.getRole() (singular) and db.getRoles().

View a Role in the Current Database

If the role is in the current database, you can refer to the role by name, as for the role dataEntry on the current database:

db.runCommand({ rolesInfo: "dataEntry" })

View a Role in a Different Database

If the role is in a different database, specify the role as a document. Use the following form:

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

To view the custom appWriter role in the orders database, issue the following command from the mongo shell:

db.runCommand({ rolesInfo: { role: "appWriter", db: "orders" } })

View Multiple Roles

To view information for multiple roles, specify each role as a document or string in an array.

To view the custom appWriter and clientWriter roles in the orders database, as well as the dataEntry role on the current database, use the following command from the mongo shell:

db.runCommand( { rolesInfo: [ { role: "appWriter", db: "orders" },
                              { role: "clientWriter", db: "orders" },
                              "dataEntry" ]
               } )

View All Custom Roles

To view the all custom roles, query admin.system.roles collection directly, for example:

db = db.getSiblingDB('admin')
db.system.roles.find()