Complete the code to create a new user with read-only access to the 'sales' database.
db.createUser({ user: "readonlyUser", pwd: "password123", roles: [ { role: [1], db: "sales" } ] })The read role grants read-only access to the specified database.
Complete the code to create a role that allows users to read and write on the 'inventory' database.
db.createRole({ role: "inventoryManager", privileges: [], roles: [ { role: [1], db: "inventory" } ] })The readWrite role allows both reading and writing data on the specified database.
Fix the error in the code to create a user with the 'userAdmin' role on the 'admin' database.
db.createUser({ user: "adminUser", pwd: "securePass", roles: [ { role: [1], db: "admin" } ] })The userAdmin role allows managing users and roles on the specified database.
Fill both blanks to create a role 'reportViewer' that can read data and run aggregation on the 'reports' database.
db.createRole({ role: "reportViewer", privileges: [ { resource: { db: "reports", collection: "" }, actions: [ [1], [2] ] } ], roles: [] })The find action allows reading data, and aggregate allows running aggregation operations.
Fill all three blanks to create a user 'dataAnalyst' with a custom role that allows reading and running aggregation on the 'analytics' database.
db.createRole({ role: [1], privileges: [ { resource: { db: [2], collection: "" }, actions: [ "find", "aggregate" ] } ], roles: [] }); db.createUser({ user: "dataAnalyst", pwd: "pass456", roles: [ { role: [1], db: [2] } ] })The custom role analyticsReader is created on the analytics database with read and aggregate privileges. The user is assigned this role.