Challenge - 5 Problems
MongoDB User and Role Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this user creation command?
Consider the following MongoDB command to create a user with readWrite role on the 'sales' database:
What will be the result of running this command if the user does not exist yet?
db.createUser({
user: "salesUser",
pwd: "pass123",
roles: [{ role: "readWrite", db: "sales" }]
})What will be the result of running this command if the user does not exist yet?
MongoDB
db.createUser({ user: "salesUser", pwd: "pass123", roles: [{ role: "readWrite", db: "sales" }] })Attempts:
2 left
💡 Hint
Creating a user with roles requires specifying the role and database correctly.
✗ Incorrect
The command creates a new user named 'salesUser' with password 'pass123' and assigns the readWrite role on the 'sales' database. MongoDB returns a success message if the user is created successfully.
📝 Syntax
intermediate2:00remaining
Which command correctly creates a role with read-only access on the 'inventory' database?
You want to create a custom role named 'inventoryRead' that allows reading any collection in the 'inventory' database. Which of the following commands is syntactically correct?
Attempts:
2 left
💡 Hint
The 'collection' field should be an empty string to specify all collections.
✗ Incorrect
Option C correctly uses 'role' as the field name, specifies the 'find' action for read access, and uses an empty string for 'collection' to mean all collections in the 'inventory' database.
❓ optimization
advanced2:00remaining
How to optimize role assignment for multiple databases?
You want to create a user who has readWrite access on both 'sales' and 'marketing' databases. Which command is the most efficient and correct way to assign these roles during user creation?
Attempts:
2 left
💡 Hint
Each role must specify a single database.
✗ Incorrect
Option A correctly assigns readWrite role separately for each database. Option A is invalid because 'db' cannot list multiple databases as a string. Options C and D lack database specification or proper role structure.
🔧 Debug
advanced2:00remaining
Why does this role creation command fail?
You run this command to create a role:
But it fails with an error. What is the most likely cause?
db.createRole({
role: "dataAnalyst",
privileges: [{ resource: { db: "analytics", collection: "reports" }, actions: ["find", "update"] }],
roles: [{ role: "read", db: "analytics" }]
})But it fails with an error. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the validity of roles referenced inside the roles array.
✗ Incorrect
The built-in role is 'read' only at the database level, but when specifying roles inside createRole, the role name must be exact and valid. 'read' is valid only if it exists on the specified database. If it does not, the command fails. Usually, 'read' is valid, but if the database or role is misspelled or missing, it causes failure. Here, the error is caused by referencing a role that does not exist or is misspelled.
🧠 Conceptual
expert2:00remaining
What is the effect of assigning the 'root' role to a user?
In MongoDB, if you create a user and assign the built-in 'root' role, what does this role allow the user to do?
Attempts:
2 left
💡 Hint
Think about the highest level of access in MongoDB.
✗ Incorrect
The 'root' role is the highest built-in role in MongoDB. It grants full administrative privileges across all databases, including the ability to manage users, roles, and perform any database operation.