0
0
MongoDBquery~30 mins

Authentication mechanisms in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Authentication Mechanisms in MongoDB
📖 Scenario: You are setting up a MongoDB database for a small company. To keep the data safe, you need to add authentication so only authorized users can access the database.
🎯 Goal: Learn how to create users with specific roles and enable authentication in MongoDB.
📋 What You'll Learn
Create a user with a username and password
Assign a role to the user
Enable authentication in the MongoDB configuration
Connect to the database using the created user credentials
💡 Why This Matters
🌍 Real World
Authentication protects sensitive data by allowing only authorized users to access the database.
💼 Career
Database administrators and developers must know how to secure MongoDB databases using authentication mechanisms.
Progress0 / 4 steps
1
Create a user with username and password
Use the db.createUser() method to create a user called appUser with password securePass123 in the admin database.
MongoDB
Need a hint?

Remember to specify the user and pwd fields inside db.createUser().

2
Assign a role to the user
Modify the db.createUser() command to assign the readWrite role on the companyDB database to appUser.
MongoDB
Need a hint?

Roles are objects with role and db fields inside the roles array.

3
Enable authentication in MongoDB configuration
Add the line security: with authorization: enabled to the MongoDB configuration file /etc/mongod.conf to enable authentication.
MongoDB
Need a hint?

This setting tells MongoDB to require users to authenticate before accessing data.

4
Connect to MongoDB using the created user
Write the MongoDB shell command to connect to companyDB as appUser using password securePass123.
MongoDB
Need a hint?

Use -u for username, -p for password, and specify --authenticationDatabase for the database where the user is created.