MongoDB Atlas Role Based Access Control

Published
Length
3 min read

Luis Felipe Dias

All posts

You use mongodb atlas role based access control to limit database actions by role. Each role lets a user or agent run specific actions on chosen resources. In MongoDB, a role applies to the database where you define it. It can grant permissions down to a single collection. MongoDB Atlas database users have different built-in roles than self-hosted users. Still, both systems build their roles from the same set of privilege actions. How mongodb atlas role based access control works in practice

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You use mongodb atlas role based access control to limit database actions by role. Each role lets a user or agent run specific actions on chosen resources.

In MongoDB, a role applies to the database where you define it. It can grant permissions down to a single collection. MongoDB Atlas database users have different built-in roles than self-hosted users. Still, both systems build their roles from the same set of privilege actions.

How mongodb atlas role based access control works in practice

Every database user and AI agent needs a role before running any query. When a person or script logs in, the database checks their assigned role. The role lists which actions are allowed on which databases and collections.

Two common built-in options are the read role and the readWrite role. The read role lets a user read all non-system collections in that database. It also covers the system.js collection. It allows actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. It blocks insert, update, remove, and dropCollection actions.

Engineers and AI agents often use the read role to check live data. This setup stops an agent or script from changing records by mistake. When a team member needs to fix data, they need the readWrite role. The readWrite role includes every permission in the read role. It also adds actions to change data and collections. These actions include insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection.

Admins can scope a role to one database or down to one collection. If an app only needs order records, you scope its role to that collection. The app cannot read or write other collections in the same database.

Security tradeoffs of static roles and collection permissions

Built-in roles give teams a clear way to separate read and write tasks. Yet collection-level roles have limits during an active database session. Once a role grants read access to a collection, the user can run find. That find action returns complete documents from the collection.

Role-Based Access Control (RBAC) + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Database roles do not filter out sensitive fields inside those returned documents. If a collection holds customer profiles, a read role returns every field in them. Those fields often include emails, phone numbers, card numbers, and national IDs. An engineer running a check or an AI agent reading context gets everything.

Static roles also stay active until an admin changes or removes them. Teams often share database accounts or keep readWrite roles assigned after a fix ends. If a key leaks, the attacker gets every action tied to that role. Also, built-in roles do not ask for peer approval before a dropCollection action runs.

To close these gaps, teams pair native roles with query-level controls. Data masking can rewrite matched fields like emails or card numbers in query results. Step-up approvals can pause risky write actions until a peer signs off. This approach keeps collection permissions intact while protecting raw fields during live sessions.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

What is the finest level of access a MongoDB role can grant?

A MongoDB role applies to the database where it is defined. Within that database, it can grant access down to the collection level. Native roles do not restrict access to individual document fields on their own.

What is the difference between the read and readWrite roles?

The read role allows actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. The readWrite role includes all read permissions plus actions that modify data. Those write actions include insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection.

Do MongoDB Atlas users have the same built-in roles as self-hosted users?

No, MongoDB Atlas database users have different built-in roles than self-hosted deployment users. Still, both sets of built-in roles use the exact same underlying privilege actions.

The query runs. The emails stay hidden.