0
0
MongoDBquery~20 mins

Role-based access control in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Role-based Access Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find users with the 'readWrite' role on the 'sales' database

Given a MongoDB collection system.users that stores user roles, which query returns all users who have the readWrite role on the sales database?

MongoDB
db.system.users.find({ roles: { $elemMatch: { role: 'readWrite', db: 'sales' } } })
Adb.system.users.find({ roles: { $elemMatch: { role: 'readWrite', db: 'sales' } } })
Bdb.system.users.find({ roles: { role: 'readWrite', db: 'sales' } })
Cdb.system.users.find({ 'roles.role': 'readWrite', 'roles.db': 'sales' })
Ddb.system.users.find({ roles: { $all: [ { role: 'readWrite' }, { db: 'sales' } ] } })
Attempts:
2 left
💡 Hint

Use $elemMatch to match both role and db in the same array element.

🧠 Conceptual
intermediate
1:30remaining
Understanding role inheritance in MongoDB

Which statement best describes how role inheritance works in MongoDB's role-based access control?

ARole inheritance only applies to system roles, not user-defined roles.
BRoles cannot inherit privileges; each role is independent and must be assigned separately.
CRoles can inherit privileges from other roles, allowing users to gain all privileges of the inherited roles.
DInheritance is automatic for all roles assigned to a user, but privileges do not combine.
Attempts:
2 left
💡 Hint

Think about how MongoDB allows roles to build on each other.

📝 Syntax
advanced
2:30remaining
Identify the syntax error in creating a custom role

Which option contains a syntax error when creating a custom role with privileges on the inventory collection?

MongoDB
db.createRole({ role: 'inventoryManager', privileges: [ { resource: { db: 'store', collection: 'inventory' }, actions: ['find', 'update'] } ], roles: [] })
Adb.createRole({ role: 'inventoryManager', privileges: [ { resource: { db: 'store', collection: 'inventory' }, actions: ['find'] } ], roles: [] })
Bdb.createRole({ role: 'inventoryManager', privileges: [ { resource: { db: 'store', collection: 'inventory' }, actions: ['find', 'update'] } ], roles: [] })
Cdb.createRole({ role: 'inventoryManager', privileges: [ { resource: { db: 'store', collection: 'inventory' }, actions: ['find', 'update'] } ] })
Ddb.createRole({ role: 'inventoryManager', privileges: { resource: { db: 'store', collection: 'inventory' }, actions: ['find', 'update'] }, roles: [] })
Attempts:
2 left
💡 Hint

Check the type of privileges field; it should be an array.

🔧 Debug
advanced
2:00remaining
Why does this user lack expected privileges?

A user was assigned the role readWrite on the reports database, but cannot insert documents into the reports collection. What is the most likely cause?

AThe user was assigned the role on the wrong database; roles are database-specific.
BThe user needs to be assigned the <code>read</code> role instead of <code>readWrite</code>.
CThe user must be assigned the <code>dbAdmin</code> role to insert documents.
DThe <code>readWrite</code> role does not include insert privileges.
Attempts:
2 left
💡 Hint

Remember that roles apply to specific databases in MongoDB.

optimization
expert
3:00remaining
Optimize role assignments for multiple users with overlapping privileges

You have multiple users needing similar but slightly different privileges on the finance database. What is the best approach to minimize management overhead while ensuring correct access?

ACreate one large role with all possible privileges and assign it to all users regardless of their needs.
BCreate a base role with common privileges and create additional roles that inherit from it for specific needs, then assign these roles to users.
CUse only built-in roles and assign multiple roles to each user to cover all privileges.
DAssign all privileges directly to each user individually to avoid role complexity.
Attempts:
2 left
💡 Hint

Think about how role inheritance can simplify privilege management.