MongoDB Database Permissions
In MongoDB, mongodb database permissions work through role-based rules that grant actions on specific resources. A role applies to a database and can restrict actions down to the collection level. Engineers and AI agents need clear rules when they query production data. Built-in roles help teams separate read actions from write actions across databases. Knowing how these roles work is the first step to safer database operations. How mongodb database permissions work in practice MongoDB uses
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.
In MongoDB, mongodb database permissions work through role-based rules that grant actions on specific resources. A role applies to a database and can restrict actions down to the collection level.
Engineers and AI agents need clear rules when they query production data. Built-in roles help teams separate read actions from write actions across databases. Knowing how these roles work is the first step to safer database operations.
How mongodb database permissions work in practice
MongoDB uses role-based rules to control what users and apps can do. Each role joins a set of allowed actions with a target resource. You assign the role on a specific database, and it applies there. A role can grant access down to a single collection.
Self-hosted setups and MongoDB Atlas use different built-in roles for database users. Still, both models build their roles from the exact same privilege actions.
For day-to-day queries, teams rely on two primary built-in roles. The read role lets users read all non-system collections and the system.js collection. It allows actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. It blocks data changes by leaving out insert, update, remove, and dropCollection.
When an engineer or app must change data, teams assign the readWrite role. This role includes every action in the read role plus data change rights. It adds insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection.
AI agents and scripts also use these same roles when they run queries. If an agent has the read role, it can inspect collections and stats. It cannot drop a collection or change documents by mistake.
Database Schema Permissions + MongoDB Authentication & Authorization: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What static roles cover and what remains exposed
Built-in roles do a good job of stopping unwanted writes in a database. Assigning the read role keeps a user from deleting records or dropping indexes. Collection-level rules also keep users out of collections they do not need.
Still, collection-level rules have a major blind spot during an active session. Once a role grants read rights on a collection, every document field returns. Native roles do not filter out sensitive fields inside an allowed collection.
Consider a customer collection that holds order totals alongside emails and card numbers. An engineer debugging an order issue needs the read role on that collection. When they run a find action, the database returns the full document. Sensitive fields like phone numbers, emails, and national IDs appear in plain text. An AI agent with the same read role also receives those raw fields.
Static database credentials create another operational burden for engineering teams. Teams often share one read or readWrite key across several people or tools. When everyone shares a user role, database logs cannot show which person ran a query. Rotating those shared keys takes manual work and can break running apps.
Managing rules across many databases also grows hard over time. Admins end up creating custom roles for every team and collection pair. Even after all that work, any allowed read query still exposes raw PII fields. Teams need a way to inspect queries and mask sensitive fields in flight.
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
How granular are native MongoDB roles?
A MongoDB role applies to the database where you define it. It can grant permissions down to the collection level of granularity. Built-in roles do not restrict individual document fields inside an allowed collection.
What is the difference between the read and readWrite roles?
The read role allows read actions like find, listCollections, and changeStream on non-system collections. The readWrite role includes all read actions and adds data modification actions. Those extra actions include insert, update, remove, createIndex, and dropCollection.
Do MongoDB Atlas and self-hosted MongoDB use the same roles?
MongoDB Atlas database users have different built-in roles than self-hosted deployment users. Still, both platforms build their roles from the exact same set of privilege actions.
Related guides
In this post