How to Configure MongoDB Read Only User
You set up a mongodb read only user by assigning the built-in read role. This role lets the user view collections in a database without changing data. Many teams give engineers full read and write roles to speed up work. Broad permissions create big risks when someone runs a bad query in production. One wrong command can delete records or change critical state across collections. Starting with a read role stops accidental edits before they happen. How to set up a mongodb read only user MongoD
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 set up a mongodb read only user by assigning the built-in read role. This role lets the user view collections in a database without changing data. Many teams give engineers full read and write roles to speed up work. Broad permissions create big risks when someone runs a bad query in production. One wrong command can delete records or change critical state across collections. Starting with a read role stops accidental edits before they happen.
How to set up a mongodb read only user
MongoDB controls access through role-based rules. A role gives a user permission to run specific actions on a target resource. Each role applies to the database where you define it. You can also scope roles down to the collection level. Self-hosted setups and MongoDB Atlas use the same core privilege actions. Yet they offer different built-in role menus to admins.
For a single database, you assign the built-in read role to the account. This role lets the user read all non-system collections in that database. It also allows reading the system JavaScript collection. The read role permits actions like finding documents and listing collections or indexes. It also allows checking database stats, checking collection stats, and opening change streams. It leaves out actions that insert, update, or remove documents. It also blocks the user from dropping collections.
In contrast, the read and write role includes every action from the read role. It adds the power to insert, update, and remove records. It also lets users create or drop collections and indexes. Keeping users on the basic read role prevents all of those write operations. If a user needs read access across multiple databases, admins assign a cluster-wide role. You define that broader role in the admin database instead of one app database.
Why native roles are only the first step
Native database roles solve an important problem for engineering teams. They block users from changing or deleting data during routine checks. A read role ensures that an engineer or analytics tool can only pull records. This protects data integrity during debugging sessions and reporting jobs.
Still, database roles only decide who logs in and which collections they can read. They do not inspect what individual queries return in flight. A read role gives full visibility into every field inside an allowed collection. If a collection holds customer records, a read query returns raw sensitive fields. Every find action pulls back emails, phone numbers, card numbers, and national IDs.
Read-Only Root Filesystem + User Provisioning (SCIM): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Role-based rules also create static credentials that teams often share. When ten people share one read account, the database logs show one user name. You cannot tell which team member ran a heavy query that slowed the cluster. You also have to rotate passwords by hand when someone leaves the team. Native roles set the baseline for safety, but they do not manage query results.
Managing credentials and query results in production
To run safe operations, teams need controls that work alongside native database roles. First, each person should log in with their own workplace identity. This removes shared database passwords from local machines and team chat rooms. It also ties every single database query to a real person in your logs.
Second, teams need field-level data masking on read queries. When a user queries a collection, masking rewrites matched fields in the results. The user still gets the document structure they need to debug an issue. Sensitive strings like emails, phone numbers, and card numbers get replaced in transit. This lets engineers read production collections safely without exposing private customer details.
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 actions can a mongodb read only user run?
The read role allows finding documents, listing collections, and listing indexes. It also allows checking database stats, checking collection stats, and opening change streams. It blocks all insert, update, remove, and drop actions.
Can you limit a read role to one collection?
Yes, MongoDB roles support access rules down to the collection level. You can create a custom role that grants find actions on one specific collection. This keeps the user from reading other collections in the same database.
Does the read role hide sensitive fields inside documents?
No, the native read role grants access to the entire document in a collection. Any query on that collection returns all fields, including emails and card numbers. To hide specific fields in results, you need data masking in front of the database.
Related guides
In this post