MongoDB User Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You manage mongodb user permissions through role-based access rules. Each role lets a user run specific actions on a database or collection. MongoDB checks these roles every time a person, app, or AI agent sends a query. A role applies to the database where you define it. It can grant access down to the collection level. Self-hosted databases and MongoDB Atlas use different built-in role lists. Both systems build those roles from the same basic privilege actions. How mongodb user permissions

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 manage mongodb user permissions through role-based access rules. Each role lets a user run specific actions on a database or collection.

MongoDB checks these roles every time a person, app, or AI agent sends a query. A role applies to the database where you define it. It can grant access down to the collection level. Self-hosted databases and MongoDB Atlas use different built-in role lists. Both systems build those roles from the same basic privilege actions.

How mongodb user permissions work in practice

Database admins assign built-in or custom roles to each user account. The standard read role lets users view all non-system collections in a database. It allows actions like finding documents, listing collections, listing indexes, and reading stats. It also allows opening a change stream on that data. The read role blocks data changes like inserts, updates, deletes, and dropping collections.

When an engineer or service needs to change data, admins grant the readWrite role. This role includes every action in the read role. It also adds actions to insert, update, and remove documents. Users with this role can create or drop collections and indexes too.

AI agents and scripts also use these same database roles. An analytics agent often uses a read role to inspect records. A backend app uses a readWrite role to save customer updates. The database checks the assigned role before running each command.

Where static database roles leave security gaps

Built-in roles stop unauthorized writes, but they have clear limits during an active session. A role grants access down to the collection level, not the field level. Once a user has the read role on a collection, every field returns in full. If a customer collection holds emails, phone numbers, card numbers, or national IDs, queries return them.

User Provisioning (SCIM) + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static credentials also create operational risk for growing engineering teams. Engineers often share database users or keep long-lived keys on laptops. If someone needs temporary write access to fix a bug, admins might grant readWrite. That broad role stays active until an admin remembers to remove it.

Also, database roles do not require peer approval for risky commands. A user with readWrite can drop a collection or delete all documents right away. Adding a query layer in front of the database helps close these gaps. Masking rewrites matched fields like emails or card numbers in query results. Command checks can pause a destructive query until a teammate approves it.

Inspect MongoDB wire traffic in flight

Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.

First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.

Frequently asked questions

What is the lowest level of access for a MongoDB role?

A MongoDB role applies to a database and can limit access down to a single collection. It does not hide individual fields inside the documents of that collection.

What is the difference between the read and readWrite roles?

The read role lets users find documents, list collections, check stats, and watch change streams. The readWrite role adds the power to insert, update, remove, and drop collections or indexes.

Do self-hosted MongoDB and MongoDB Atlas use the exact same roles?

No, MongoDB Atlas database users have different built-in roles than self-hosted database users. Still, both platforms build their roles from the same underlying privilege actions.

Teams that document these role rules and review logs each month catch config drift early. Clear ownership for each role keeps live systems simple to run and easy to audit across the whole team.

The query runs. The emails stay hidden.