How to Configure MongoDB Proxy
To set up a mongodb proxy, you route client traffic through a middle server. This server checks user rules and sends allowed requests to your database cluster. Many teams start by giving users direct database roles instead. When teams assign broad roles for speed, one mistake can change or delete whole collections. How native roles work before adding a mongodb proxy MongoDB uses role-based rules to control what users can do. A role lets a user run a set of actions on specific database targets
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.
To set up a mongodb proxy, you route client traffic through a middle server. This server checks user rules and sends allowed requests to your database cluster. Many teams start by giving users direct database roles instead. When teams assign broad roles for speed, one mistake can change or delete whole collections.
How native roles work before adding a mongodb proxy
MongoDB uses role-based rules to control what users can do. A role lets a user run a set of actions on specific database targets. Each role works on the database where an admin defines it. You can narrow these permissions down to a single collection.
Self-hosted clusters and MongoDB Atlas have different built-in roles for database users. Still, both setups use the exact same set of underlying privilege actions. Most teams start with two common built-in roles for daily work.
The read role lets a user read all non-system collections in that database. It also lets them read one specific system JavaScript collection. This role allows actions that find documents, list collections, and list indexes. It also allows checking database stats, checking collection stats, and opening change streams. It blocks users from adding, changing, or deleting documents, and from dropping collections.
When a user needs to fix data, admins often give them the readWrite role. This role includes every action from the read role plus data change rights. Users with this role can add, update, and remove documents in the database. They can also create or drop collections and create or drop indexes.
What native database roles solve and what they miss
Native roles are great for sorting users into clear buckets. You can give analysts the read role so they only run find actions. You can give apps the readWrite role so they can save new records. You can even limit a custom role to one specific collection.
Still, native roles only check permissions down to the collection level. Once a user has the read role, they can read every field in that collection. If a collection holds emails, phone numbers, or card numbers, the read role returns them. Native roles do not rewrite matched fields in query results on the fly.
Database Proxy (ProxySQL, PgBouncer) + MongoDB Authentication & Authorization: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The readWrite role leaves an even larger gap during live incidents. An engineer might need to update one bad document during an outage. If you grant the readWrite role, that engineer can also drop collections or indexes. Native roles decide who logs in and which actions they can run on a collection. They do not check what each single command does while it runs in flight.
Why teams pair collection roles with query checks
Relying only on static roles forces teams into a hard choice. If you lock down roles too much, engineers cannot fix broken records fast. If you hand out the readWrite role, anyone can run a drop action by mistake. Sharing one role across a whole team also makes audit logs hard to read.
Teams solve this by pairing collection roles with per-command checks and field masking. A good setup checks who sends each command before the database runs it. It also rewrites sensitive fields like national IDs or card numbers in query results. This keeps everyday work safe without giving out standing drop rights to the team.
Check MongoDB commands and documents on the wire
MongoDB roles and SCRAM login decide who opens a session. They do not check single commands or redact sensitive fields inside returned documents. With hoop.dev, you run an open-source proxy, a sidecar for your MongoDB, inline in the MongoDB wire protocol. On every command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13, or hold risky commands for approval. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents in memory, and every verdict is logged. See the open-source code on GitHub.
Frequently asked questions
Can native MongoDB roles restrict access below the collection level?
No, native roles grant actions down to the collection level. They do not limit which fields or documents a user can read inside that collection.
What is the difference between the read and readWrite roles in MongoDB?
The read role allows finding data, listing indexes, and viewing stats. The readWrite role adds rights to insert, update, remove data, and drop collections or indexes.
Do MongoDB Atlas and self-hosted MongoDB use the same roles?
MongoDB Atlas database users have different built-in roles than self-hosted users. Still, both setups build their roles from the same set of privilege actions.
Related guides
In this post