MongoDB Role Management CommandsThe role management commands are used to define the role for the specified user. MongoDB createRole commandThe createRole command assigns a role and specifies its advantages. The assigned role applies to the database on which we run the command. The command returns a duplicate role error if the role already exists in the database. Syntax: Command fields:
Example: The createRole command creates the JavaTpointAdmin role on the admin database MongoDB dropRole commandThe MongoDB dropRole command deletes the role that is defined by the user in the database on which we run the command. Syntax: MongoDB updateRoleThe update command updates the user-defined role. The command must run on the role's database. This command can replace the previous field value completely. Syntax: Example: The above example updates the myClusterwideAdmin role on the admin database. MongoDB grantPrivilagesToRole commandThis is a very important command which is used to add some extra privileges to a user-defined role on the database where the command is used to run. Syntax: Example: The above example grants two additional privilages to the service role that exists in the product database. Next TopicMongoDB Replication Command |