Challenge - 5 Problems
MongoDB Role Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of creating a custom role with specific privileges
You create a custom role in MongoDB with the following command:
What will be the effect of this role when assigned to a user?
db.getSiblingDB('admin').runCommand({
createRole: "readWriteReports",
privileges: [
{
resource: { db: "reports", collection: "monthly" },
actions: ["find", "insert"]
}
],
roles: []
})What will be the effect of this role when assigned to a user?
Attempts:
2 left
💡 Hint
Look carefully at the resource specification and the actions allowed.
✗ Incorrect
The role specifies privileges only on the 'monthly' collection in the 'reports' database with 'find' and 'insert' actions. So the user can only read and insert documents there, not elsewhere.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this custom role creation command
Which option contains a syntax error when creating a custom role in MongoDB?
MongoDB
db.getSiblingDB('admin').runCommand({ createRole: "dataAnalyst", privileges: [ { resource: { db: "analytics", collection: "" }, actions: ["find", "update"] } ], roles: [] })
Attempts:
2 left
💡 Hint
Check the resource field values carefully.
✗ Incorrect
An empty string for collection means no collection specified, which is invalid. To specify all collections, use '*' or omit the collection field.
🧠 Conceptual
advanced2:00remaining
Understanding role inheritance in custom roles
You create a custom role 'manager' that inherits from the built-in 'readWrite' role on the 'sales' database. What privileges does the 'manager' role have?
Attempts:
2 left
💡 Hint
Think about how role inheritance works in MongoDB.
✗ Incorrect
When a custom role inherits from another role, it gains all privileges of the inherited role plus any additional privileges defined.
🔧 Debug
advanced2:00remaining
Why does this custom role creation command fail?
Consider this command:
Why does this command fail?
db.getSiblingDB('admin').runCommand({
createRole: "auditor",
privileges: [
{
resource: { db: "", collection: "logs" },
actions: ["find"]
}
],
roles: []
})Why does this command fail?
Attempts:
2 left
💡 Hint
Check the resource fields for correctness.
✗ Incorrect
The database field cannot be empty. It must specify a valid database name or use '*' for all databases.
❓ optimization
expert2:00remaining
Optimizing custom role privileges for minimal access
You want to create a custom role that allows a user to only update documents in the 'inventory' collection of the 'store' database, but no other actions or collections. Which command achieves this with the least privileges?
Attempts:
2 left
💡 Hint
Minimize both the resource scope and actions allowed.
✗ Incorrect
Option A restricts privileges exactly to the 'inventory' collection in 'store' database with only 'update' action, minimizing access.