What does the read built-in role in MongoDB allow a user to do?
The read role allows a user to read data from all non-system collections and views in a database. It does not allow any write or administrative actions.
Click to reveal answer
beginner
What permissions does the readWrite role grant in MongoDB?
The readWrite role allows a user to read and write data on all non-system collections and views in a database. This includes inserting, updating, and deleting documents.
Click to reveal answer
intermediate
What is the purpose of the dbAdmin role in MongoDB?
The dbAdmin role provides administrative privileges on a database, such as creating and modifying indexes, viewing statistics, but it does not allow reading or writing data.
Click to reveal answer
beginner
Can a user with the read role modify data in MongoDB?
No, a user with the read role can only view data. They cannot insert, update, or delete any documents.
Click to reveal answer
intermediate
Which built-in MongoDB role should you assign to a user who needs to manage indexes but not modify data?
You should assign the dbAdmin role because it allows managing indexes and other administrative tasks without granting read or write access to data.
Click to reveal answer
Which MongoDB built-in role allows a user to only read data but not modify it?
Aread
BreadWrite
CdbAdmin
Droot
✗ Incorrect
The 'read' role grants read-only access to data without any write or admin privileges.
What actions can a user with the 'readWrite' role perform?
ARead and write data
BOnly read data
CManage users
DOnly manage indexes
✗ Incorrect
The 'readWrite' role allows both reading and modifying data in the database.
Which role is best for a user who needs to create indexes but should not read or write data?
AreadWrite
BdbAdmin
Cread
Dbackup
✗ Incorrect
The 'dbAdmin' role allows administrative tasks like creating indexes without data access.
Does the 'dbAdmin' role allow a user to delete documents?
AYes
BOnly if combined with readWrite
CNo
DOnly on system collections
✗ Incorrect
The 'dbAdmin' role does not grant permissions to modify data, including deleting documents.
If a user needs full read and write access to a database, which role should they have?
Aread
BdbAdmin
CclusterAdmin
DreadWrite
✗ Incorrect
The 'readWrite' role provides full read and write access to the database.
Explain the differences between the MongoDB built-in roles: read, readWrite, and dbAdmin.
Think about what each role lets a user do with data and database management.
You got /4 concepts.
Describe a real-life scenario where you would assign the dbAdmin role instead of readWrite or read.
Consider tasks that involve managing the database but not changing data.
You got /3 concepts.
Practice
(1/5)
1. Which built-in MongoDB role allows a user to only view data without making any changes?
easy
A. root
B. readWrite
C. dbAdmin
D. read
Solution
Step 1: Understand the read role
The read role allows users to view data but not modify it.
Step 2: Compare with other roles
readWrite allows changes, dbAdmin manages settings, root has full access.
Final Answer:
read -> Option D
Quick Check:
View-only permission = read [OK]
Hint: View-only means read role [OK]
Common Mistakes:
Confusing readWrite with read
Thinking dbAdmin allows data viewing only
Assuming root is for read-only
2. Which of the following is the correct way to assign the readWrite role to a user on the database mydb in MongoDB shell?
easy
A. db.grantRolesToUser('username', [{role: 'readWrite', db: 'mydb'}])
B. db.createUser({user: 'username', roles: ['readWrite']})
C. db.grantRolesToUser('username', ['readWrite'])
D. db.grantRolesToUser('username', [{role: 'readWrite', db: 'admin'}])
Solution
Step 1: Check syntax for granting roles
The correct syntax uses db.grantRolesToUser with an array of role objects specifying role and database.
Step 2: Validate database name and role format
db.grantRolesToUser('username', [{role: 'readWrite', db: 'mydb'}]) correctly specifies role as 'readWrite' and database as 'mydb'. db.grantRolesToUser('username', [{role: 'readWrite', db: 'admin'}]) wrongly uses 'admin' database.
Final Answer:
db.grantRolesToUser('username', [{role: 'readWrite', db: 'mydb'}]) -> Option A
Quick Check:
Grant role with role+db object array [OK]
Hint: Use role objects with db name in array for granting roles [OK]
Common Mistakes:
Passing roles as simple strings without db
Using wrong database name for the role
Using createUser instead of grantRolesToUser for existing users
3. Given a user with the dbAdmin role on database sales, which of the following actions can the user perform?
medium
A. Create and drop indexes on collections
B. Insert new documents into collections
C. Read documents from collections
D. Modify documents in collections
Solution
Step 1: Understand dbAdmin role capabilities
The dbAdmin role allows managing database settings like indexes, stats, and users, but not data changes.
Step 2: Match actions to role permissions
Creating/dropping indexes is a dbAdmin task. Inserting, reading, or modifying documents require readWrite or read roles.
Final Answer:
Create and drop indexes on collections -> Option A
Quick Check:
dbAdmin manages indexes, not data changes [OK]
Hint: dbAdmin manages indexes, not data content [OK]
Common Mistakes:
Assuming dbAdmin can insert or modify data
Confusing readWrite with dbAdmin
Thinking dbAdmin can read data
4. You tried to assign the readWrite role to a user with this command: db.grantRolesToUser('alice', ['readWrite']) But it failed. What is the likely cause?
medium
A. The user 'alice' does not exist
B. The role array must contain objects with role and db fields
C. The readWrite role does not exist
D. You must use createUser to assign roles
Solution
Step 1: Check syntax for grantRolesToUser
The method requires an array of role objects with role and db fields, not just strings.
Step 2: Analyze the given command
The command uses an array of strings, which is invalid syntax and causes failure.
Final Answer:
The role array must contain objects with role and db fields -> Option B
Quick Check:
Roles must be objects with role and db [OK]
Hint: Roles need role+db objects, not strings [OK]
Common Mistakes:
Passing roles as strings instead of objects
Assuming createUser is needed to add roles to existing users
Ignoring user existence errors
5. You want a user to manage database indexes and view data but not modify documents. Which combination of built-in roles should you assign?
hard
A. readWrite only
B. dbAdmin only
C. read and dbAdmin
D. readWrite and dbAdmin
Solution
Step 1: Identify roles for viewing data and managing indexes