What is Role-based Access Control (RBAC) in MongoDB?
RBAC is a way to manage who can do what in MongoDB by assigning roles to users. Each role has specific permissions that control access to database actions.
Click to reveal answer
intermediate
How do you create a custom role in MongoDB?
Use the db.createRole() command with a role name, privileges (actions on resources), and optionally inherited roles.
Click to reveal answer
beginner
What is the difference between a built-in role and a custom role in MongoDB?
Built-in roles come predefined with MongoDB and cover common permissions. Custom roles are created by users to tailor permissions for specific needs.
Click to reveal answer
beginner
Which MongoDB command assigns a role to a user?
The db.grantRolesToUser() command assigns one or more roles to an existing user.
Click to reveal answer
beginner
Why is it important to follow the principle of least privilege in RBAC?
It limits users to only the permissions they need, reducing the risk of accidental or malicious data access or changes.
Click to reveal answer
Which command creates a new role in MongoDB?
Adb.createRole()
Bdb.createUser()
Cdb.grantRolesToUser()
Ddb.addRole()
✗ Incorrect
Use db.createRole() to define a new role with specific privileges.
What does a role in MongoDB define?
AA set of permissions
BA collection
CA database
DA set of users
✗ Incorrect
A role defines permissions that control what actions a user can perform.
Which command assigns roles to an existing user?
Adb.createUser()
Bdb.grantRolesToUser()
Cdb.createRole()
Ddb.addUserRole()
✗ Incorrect
db.grantRolesToUser() is used to assign roles to users.
What is the principle of least privilege?
AUsers get all permissions
BUsers get no permissions
CUsers share permissions
DUsers get only permissions they need
✗ Incorrect
It means users should have only the permissions necessary to do their job.
Which of these is NOT a built-in MongoDB role?
AreadWrite
BdbAdmin
CsuperUser
Dread
✗ Incorrect
There is no built-in role named superUser in MongoDB.
Explain how role-based access control works in MongoDB and why it is useful.
Think about how you give keys to rooms only to people who need them.
You got /4 concepts.
Describe the steps to create a custom role and assign it to a user in MongoDB.
First create the role, then give it to the user.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of role-based access control (RBAC) in MongoDB?
easy
A. To optimize query performance automatically
B. To store data in a structured format
C. To manage user permissions by assigning roles with specific privileges
D. To backup the database regularly
Solution
Step 1: Understand RBAC concept
RBAC is about controlling what users can do by giving them roles with permissions.
Step 2: Identify RBAC purpose in MongoDB
MongoDB uses RBAC to assign roles that define user privileges, managing access securely.
Final Answer:
To manage user permissions by assigning roles with specific privileges -> Option C
Quick Check:
RBAC controls access by roles = A [OK]
Hint: RBAC controls user actions via roles, not data or backups [OK]
Common Mistakes:
Confusing RBAC with data storage
Thinking RBAC handles backups
Assuming RBAC optimizes queries
2. Which of the following is the correct syntax to create a role named readOnlyUser with read access on the sales database?
A. The field 'role' should be 'name' when creating a role
B. The 'actions' array cannot contain 'update'
C. The 'resource' field must include 'collection' as null, not a string
D. Roles cannot have empty 'roles' array
Solution
Step 1: Check role creation syntax
The correct field to name a role is 'name', not 'role'. Using 'role' causes failure.
Step 2: Validate other fields
Actions like 'update' are valid, collection as string is correct, and empty roles array is allowed.
Final Answer:
The field 'role' should be 'name' when creating a role -> Option A
Quick Check:
Use 'name' field for role creation = B [OK]
Hint: Use 'name' not 'role' to name roles in createRole [OK]
Common Mistakes:
Using 'role' instead of 'name' for role name
Thinking 'update' is invalid action
Believing empty roles array is disallowed
5. You want to create a custom role manager that can read and update documents in the employees database and also inherit all privileges from the built-in read role on the same database. Which command correctly achieves this?