MongoDB Role Management Commands
The role management commands are used to define the role for the specified user.
MongoDB createRole command
The 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.
The createRole command creates the JavaTpointAdmin role on the admin database
MongoDB dropRole command
The MongoDB dropRole command deletes the role that is defined by the user in the database on which we run the command.
The 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.
The above example updates the myClusterwideAdmin role on the admin database.
MongoDB grantPrivilagesToRole command
This 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.
The above example grants two additional privilages to the service role that exists in the product database.