Concept Flow - Built-in roles (read, readWrite, dbAdmin)
Start: User needs permissions
Choose built-in role
read
Access granted based on role
End
User selects one built-in role to get specific database permissions: read, readWrite, or dbAdmin.
use mydb
db.createUser({
user: "alice",
roles: ["readWrite"]
})| Step | Action | Role Assigned | Permissions Granted | Result |
|---|---|---|---|---|
| 1 | Switch to database 'mydb' | N/A | N/A | Context set to 'mydb' |
| 2 | Create user 'alice' with role 'readWrite' | readWrite | Read and write data on 'mydb' | User 'alice' created |
| 3 | User 'alice' tries to read data | readWrite | Allowed | Read operation successful |
| 4 | User 'alice' tries to write data | readWrite | Allowed | Write operation successful |
| 5 | User 'alice' tries to perform admin task | readWrite | Denied | Operation failed: insufficient privileges |
| 6 | End | N/A | N/A | User permissions enforced based on role |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|
| user | undefined | alice (readWrite) | alice (readWrite) | alice (readWrite) | alice (readWrite) |
| permissions | none | read and write | read allowed | read and write allowed | read and write allowed |
Built-in roles in MongoDB control user permissions. read: can only read data. readWrite: can read and write data. dbAdmin: can manage database structure. Assign roles when creating users to control access. Permissions are enforced automatically by MongoDB.
read roleread role allows users to view data but not modify it.readWrite allows changes, dbAdmin manages settings, root has full access.read -> Option Dread [OK]read role [OK]readWrite with readdbAdmin allows data viewing onlyroot is for read-onlyreadWrite role to a user on the database mydb in MongoDB shell?db.grantRolesToUser with an array of role objects specifying role and database.dbAdmin role on database sales, which of the following actions can the user perform?dbAdmin role capabilitiesdbAdmin role allows managing database settings like indexes, stats, and users, but not data changes.readWrite or read roles.readWrite role to a user with this command:db.grantRolesToUser('alice', ['readWrite'])role and db fields, not just strings.read allows viewing data, dbAdmin allows managing indexes and database settings.readWrite allows modifying documents, which is not desired here.read and dbAdmin -> Option CPass the test and this pattern moves unknown