How to Configure Amazon Q MongoDB Read Only Access
You set up amazon q mongodb read only access by creating a dedicated database user. Assign the built-in read role to that user on your target database. Engineering teams often connect coding assistants using shared local keys or broad admin accounts. This shortcut saves time during setup, but it exposes live data to accidental edits. If an AI agent runs a bad command, broad roles allow data loss. Scoping the database account down to read actions stops write operations at the database engine. H
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 amazon q mongodb read only access by creating a dedicated database user. Assign the built-in read role to that user on your target database. Engineering teams often connect coding assistants using shared local keys or broad admin accounts. This shortcut saves time during setup, but it exposes live data to accidental edits. If an AI agent runs a bad command, broad roles allow data loss. Scoping the database account down to read actions stops write operations at the database engine.
How amazon q mongodb read only access works in native roles
MongoDB controls who can do what through role-based rules. A role gives a user permission to run specific actions on a resource. Each role applies to the database where you define it. You can also scope custom roles down to the collection level. Self-hosted setups and cloud clusters offer different built-in role lists. Both systems build their roles from the same core privilege actions.
For a coding assistant, you start with the built-in read role. This role lets the user read all non-system collections in that database. It allows actions like finding documents, listing collections, and checking index lists. It also lets the user view database stats, collection stats, and change streams. The read role leaves out actions that insert, update, or remove documents. It also blocks the user from dropping collections or changing index structures. By contrasting this with the read-write role, the safety benefit is clear. The read-write role adds actions that create, change, and delete data and indexes.
When Amazon Q runs local database queries or tools, it uses the credentials you supply. You create a dedicated database user just for the assistant. Next, you attach the read role for the specific database the agent needs. Then you pass those user credentials to the local tool or shell environment. When the assistant sends a find command, the database checks the role and runs it. If the assistant tries to delete a record, the database rejects the command.
What native roles solve and what they leave open
Native database roles solve the problem of unauthorized writes and schema drops. A user with the read role cannot alter records or wipe out a collection. This protects your data integrity when an AI tool suggests or runs a bad command. It is a necessary first step for any team connecting assistants to data stores.
Still, database roles only check who logs in and which command type they send. The read role applies to every document inside the allowed collections. It does not inspect the content of the records that return in a query. If a collection holds customer records, a read role returns every field in those documents. Raw emails, phone numbers, card numbers, and national IDs flow back to the local machine. From there, those sensitive fields can enter the AI model prompt and context window.
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.
Static roles also create secret management headaches for engineering teams. Developers must store the database password or connection string on their laptops. Those static credentials sit in plain text config files or shell variables until someone rotates them. Also, standard role checks do not ask a human to approve a heavy query first. An AI agent with read rights can still run a full collection scan that slows production.
Why teams add runtime checks for AI database queries
To close these gaps, teams look beyond static user roles on the database server. They focus on controlling individual commands and query results while traffic is in flight. Instead of handing static database passwords to developer laptops, teams tie sessions to user identity. Every query links back to a specific person and their active session.
Runtime inspection also changes how sensitive fields reach the coding assistant. Rather than returning raw documents, data masking rewrites matched fields in query results. Sensitive values like emails, phone numbers, and card numbers get masked before reaching the client. The assistant still sees the document structure and non-sensitive fields to help write code. Finally, teams can require quick peer approval before an agent touches sensitive collections.
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 runs beside your database as a sidecar for your MongoDB. It checks every wire command and result document without changing your drivers or credentials.
Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run. 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
What is the difference between the MongoDB read and readWrite roles?
The read role allows finding documents, listing collections, listing indexes, and viewing database stats. The readWrite role includes all read actions plus inserting, updating, removing, and dropping collections.
Can I restrict a MongoDB role to a single collection for Amazon Q?
Yes, MongoDB roles can grant access down to the individual collection level. You can build a custom role that grants find actions on only the collections your assistant needs.
Does the MongoDB read role hide sensitive fields like emails or card numbers?
No, the native read role grants read permissions to whole documents within the allowed collections. To mask fields like emails, phone numbers, or card numbers in results, you need runtime data masking.
Related guides
In this post