How to Configure Goose MongoDB Read Only Access
You set up goose mongodb read only access by giving a database user the built-in read role. Then you pass those login keys to your AI agent so it can query data without changing it. Many teams start by reusing an old admin account or a write role to save time. That shortcut lets an automated agent drop collections, alter documents, or delete records if a prompt goes wrong. How native goose mongodb read only access works MongoDB uses roles to control what a user can do after logging in. Each r
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 goose mongodb read only access by giving a database user the built-in read role. Then you pass those login keys to your AI agent so it can query data without changing it. Many teams start by reusing an old admin account or a write role to save time. That shortcut lets an automated agent drop collections, alter documents, or delete records if a prompt goes wrong.
How native goose mongodb read only access works
MongoDB uses roles to control what a user can do after logging in. Each role grants a set of actions on a specific resource. A role applies to the database where you define it. You can also scope custom roles down to the collection level when you need tighter rules. MongoDB Atlas and self-hosted setups use different built-in role lists, though both share the same base actions.
The built-in read role is the standard choice for an AI agent. It lets the user read all non-system collections and the system JavaScript collection in that database. Under the hood, this role grants actions to find documents, list collections, list indexes, and check stats. It also allows change streams on those collections. Crucially, the read role leaves out actions that insert, update, or remove documents, or drop collections.
By contrast, the read and write role includes every read action plus full power to change data. It lets a user insert, update, and remove documents across the database. It also allows creating or dropping collections and indexes. Giving that role to Goose means any bad tool call can alter your live data. Keeping the agent on the read role stops write commands at the database engine.
Why native roles alone leave gaps in production
Database roles solve a clear problem by deciding who can log in and what actions they can run. Once the read role is set, the database blocks any write attempt from that account. Still, native roles stop checking after they approve the action type and target collection. They do not inspect what individual queries do in flight or what raw values return to the client.
When Goose runs a find action on a user collection, the read role allows the whole document back. If that document holds emails, phone numbers, card numbers, or national IDs, those values flow straight into the agent context. The database role has no native way to rewrite matched fields in results for a standard read user. You either grant read rights to the whole collection or block the collection completely.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing static database keys on engineer laptops also creates work for security teams. To run local Goose sessions, developers often store connection strings with passwords in local files. If a developer leaves the team or a laptop is lost, you must rotate those shared database keys by hand. Native roles also tie audit logs to the shared database account instead of the person running the prompt.
Scoping collection permissions and managing agent queries
Teams that need tighter boundaries often build custom roles instead of using database-wide read roles. Because MongoDB roles work down to the collection level, you can allow find actions on safe tables only. You can leave sensitive billing or account collections out of the custom role definition. This keeps the agent away from tables it never needs to touch during normal coding tasks.
Even with collection rules, safe collections still contain mixed data fields and heavy workloads. An agent with read rights can still run an unindexed find query that scans millions of documents. It can also pull user emails or card numbers stored inside general app logs or order records. Teams need a way to inspect queries and mask sensitive values before results reach the agent.
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. It reads the MongoDB wire protocol and checks commands and bulk writes as JSON while passing login through untouched.
Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents that match your rules. Every command and verdict is logged. See the open-source code on GitHub.
Frequently asked questions
What is the difference between the MongoDB read role and readWrite role for Goose?
The read role lets Goose find documents and view collection stats without changing any data. The read and write role adds actions to insert, update, remove, and drop collections, which risks data loss.
Can MongoDB restrict Goose to specific collections instead of the whole database?
Yes, MongoDB roles can grant privileges down to the collection level. You can create a custom role that allows find actions only on the exact collections Goose needs.
Does the MongoDB read role hide sensitive fields like emails or card numbers?
No, the native read role grants read rights to the entire document in allowed collections. To hide emails, phone numbers, card numbers, or national IDs, you need data masking that rewrites matched fields in results.
Related guides
In this post