0
0
MongoDBquery~30 mins

Built-in roles (read, readWrite, dbAdmin) in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Using MongoDB Built-in Roles: read, readWrite, dbAdmin
📖 Scenario: You are managing a small company's database using MongoDB. Different team members need different access levels to the database collections. You will assign built-in roles to users to control their permissions.
🎯 Goal: Assign MongoDB built-in roles read, readWrite, and dbAdmin to users on a database called companyDB.
📋 What You'll Learn
Create three users with exact usernames: readerUser, writerUser, and adminUser
Assign the read role on companyDB to readerUser
Assign the readWrite role on companyDB to writerUser
Assign the dbAdmin role on companyDB to adminUser
💡 Why This Matters
🌍 Real World
In real companies, database access must be controlled carefully. Assigning built-in roles helps secure data and limits user actions to what they need.
💼 Career
Database administrators and backend developers often create and manage users with roles to protect data and ensure proper access control.
Progress0 / 4 steps
1
Create the readerUser with read role
Use the db.createUser() command to create a user named readerUser with password readerPass123 and assign the built-in role read on the database companyDB.
MongoDB
Need a hint?

The read role allows the user to read data but not modify it.

2
Create the writerUser with readWrite role
Use the db.createUser() command to create a user named writerUser with password writerPass123 and assign the built-in role readWrite on the database companyDB.
MongoDB
Need a hint?

The readWrite role allows the user to read and write data in the database.

3
Create the adminUser with dbAdmin role
Use the db.createUser() command to create a user named adminUser with password adminPass123 and assign the built-in role dbAdmin on the database companyDB.
MongoDB
Need a hint?

The dbAdmin role allows the user to manage the database, including indexes and statistics, but not read or write data.

4
Verify all users are created with correct roles
Use the db.getUsers() command to list all users and verify that readerUser, writerUser, and adminUser exist with their assigned roles on companyDB.
MongoDB
Need a hint?

This command shows all users and their roles on the current database.