Create a Custom Role in MongoDB
📖 Scenario: You are a database administrator for a small company. You need to create a custom role in MongoDB that allows users to read data from the sales database and insert documents into the feedback collection within the customer database.
🎯 Goal: Build a MongoDB custom role named readSalesInsertFeedback with the exact privileges to read from the sales database and insert into the feedback collection of the customer database.
📋 What You'll Learn
Create a role named
readSalesInsertFeedbackGrant
find action on all collections in the sales databaseGrant
insert action on the feedback collection in the customer databaseUse the
db.createRole() method with the correct structure💡 Why This Matters
🌍 Real World
Custom roles help control exactly what users can do in a MongoDB database, improving security and organization.
💼 Career
Database administrators and developers often create custom roles to tailor access permissions to business needs.
Progress0 / 4 steps