A custom role in MongoDB is a user-defined set of privileges that control access to database actions, allowing fine-tuned permission management beyond built-in roles.
Click to reveal answer
beginner
Which command is used to create a custom role in MongoDB?
The db.createRole() command is used to create a custom role in MongoDB.
Click to reveal answer
intermediate
What are the main components you must specify when creating a custom role?
You must specify the role name, privileges (actions and resources), and optionally roles to inherit from other roles.
Click to reveal answer
intermediate
How do you assign a custom role to a user in MongoDB?
Use the db.grantRolesToUser() command to assign a custom role to a user.
Click to reveal answer
intermediate
Can a custom role inherit privileges from built-in roles in MongoDB?
Yes, a custom role can inherit privileges by including built-in roles in its roles array during creation.
Click to reveal answer
Which MongoDB command creates a custom role?
Adb.createUser()
Bdb.addRole()
Cdb.createRole()
Ddb.grantRolesToUser()
✗ Incorrect
The db.createRole() command is specifically used to create custom roles.
What must you specify when defining privileges for a custom role?
ADatabase size
BActions and resources
COnly user names
DNetwork settings
✗ Incorrect
Privileges require specifying the actions allowed and the resources those actions apply to.
How do you assign a custom role to a user?
Adb.grantRolesToUser()
Bdb.createRole()
Cdb.createUser()
Ddb.assignRole()
✗ Incorrect
The db.grantRolesToUser() command assigns roles, including custom roles, to users.
Can a custom role include other roles?
AOnly user roles can be included
BNo, roles are always standalone
COnly built-in roles can be included
DYes, it can inherit other roles
✗ Incorrect
Custom roles can inherit privileges by including other roles in their definition.
Which of these is NOT a valid privilege action in MongoDB custom roles?
Acompile
Binsert
Cdelete
Dfind
✗ Incorrect
Actions like find, insert, and delete are valid; compile is not a MongoDB privilege action.
Explain how to create a custom role in MongoDB and what key parts you need to define.
Think about the command and the structure of the role document.
You got /4 concepts.
Describe the process to assign a custom role to a user in MongoDB.
Focus on the command that links roles to users.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of creating a custom role in MongoDB?
easy
A. To speed up database queries
B. To assign specific permissions tailored to user needs
C. To backup the database automatically
D. To create new collections in the database
Solution
Step 1: Understand role purpose
Custom roles are designed to control what actions a user can perform.
Step 2: Match purpose to options
Only To assign specific permissions tailored to user needs describes assigning specific permissions tailored to user needs.
Final Answer:
To assign specific permissions tailored to user needs -> Option B
Quick Check:
Custom role purpose = Assign specific permissions [OK]
Hint: Custom roles control user permissions precisely [OK]
Common Mistakes:
Confusing roles with database backups
Thinking roles speed up queries
Assuming roles create collections
2. Which of the following is the correct syntax to create a custom role named readWriteReports with read and write privileges on the reports database?
A. The 'actions' field should be an array, not a string
B. The 'resource' field is missing the database name
C. The 'name' field should be 'role'
D. The 'roles' array cannot be empty
Solution
Step 1: Check 'actions' field type
The 'actions' field must be an array of strings, but here it is a single string "update".
Step 2: Verify other fields
The 'resource' includes both db and collection correctly; 'name' is correct; 'roles' can be empty.
Final Answer:
The 'actions' field should be an array, not a string -> Option A
Quick Check:
'actions' must be an array [OK]
Hint: Always use array for 'actions' even if one action [OK]
Common Mistakes:
Using string instead of array for 'actions'
Confusing 'name' with 'role' field
Thinking 'roles' array cannot be empty
5. You want to create a custom role reportManager that allows users to read all collections in the reports database and also run the aggregate action on the summary collection only. Which of the following commands correctly implements this?