0
0
MongoDBquery~10 mins

Role-based access control in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new role named 'readRole' with read-only privileges on the 'sales' database.

MongoDB
db.createRole({ role: 'readRole', privileges: [{ resource: { db: 'sales', collection: '' }, actions: ['[1]'] }], roles: [] })
Drag options to blanks, or click blank then click option'
Aread
BuserAdmin
CdbAdmin
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'write' instead of 'read' grants write permissions, which is not read-only.
Confusing 'dbAdmin' or 'userAdmin' with read privileges.
2fill in blank
medium

Complete the code to grant the built-in role 'readWrite' on the 'inventory' database to the user 'alice'.

MongoDB
db.grantRolesToUser('alice', [{ role: '[1]', db: 'inventory' }])
Drag options to blanks, or click blank then click option'
Aread
BreadWrite
CdbAdmin
DuserAdmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read' only grants read access, not write.
Using 'dbAdmin' or 'userAdmin' grants administrative privileges, not data access.
3fill in blank
hard

Fix the error in the command to revoke the 'readWrite' role from user 'bob' on the 'reports' database.

MongoDB
db.revokeRolesFromUser('bob', [{ role: '[1]', db: 'reports' }])
Drag options to blanks, or click blank then click option'
AreadWrite
BdbAdmin
Cread
DuserAdmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read' only revokes read permissions, leaving write intact.
Using 'dbAdmin' or 'userAdmin' revokes unrelated roles.
4fill in blank
hard

Fill both blanks to create a role 'customAdmin' with privileges to manage users and roles on the 'admin' database.

MongoDB
db.createRole({ role: 'customAdmin', privileges: [{ resource: { db: '[1]', collection: '' }, actions: ['[2]'] }], roles: [] })
Drag options to blanks, or click blank then click option'
Aadmin
Bread
CuserAdmin
DreadWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'read' or 'readWrite' actions instead of 'userAdmin'.
Specifying the wrong database other than 'admin'.
5fill in blank
hard

Fill all three blanks to create a role 'reportWriter' that can read from 'reports' and write to 'logs' databases.

MongoDB
db.createRole({ role: 'reportWriter', privileges: [{ resource: { db: '[1]', collection: '' }, actions: ['read'] }, { resource: { db: '[2]', collection: '' }, actions: ['[3]'] }], roles: [] })
Drag options to blanks, or click blank then click option'
Areports
Blogs
Cwrite
DreadWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'readWrite' action instead of just 'write' for the second privilege.
Mixing up the database names for read and write.