How to Configure Amazon Q MongoDB Prevent Delete
You set up an amazon q mongodb prevent delete rule by limiting database roles. Assign a read-only role or build a custom role without remove and drop actions. Engineering teams often connect coding assistants to live databases using shared developer keys. Those keys usually carry broad read and write powers across every collection. When an AI tool runs a bad script, broad roles allow accidental data loss. How to set up amazon q mongodb prevent delete roles MongoDB controls user actions throug
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 an amazon q mongodb prevent delete rule by limiting database roles. Assign a read-only role or build a custom role without remove and drop actions. Engineering teams often connect coding assistants to live databases using shared developer keys. Those keys usually carry broad read and write powers across every collection. When an AI tool runs a bad script, broad roles allow accidental data loss.
How to set up amazon q mongodb prevent delete roles
MongoDB controls user actions through role-based rules on each database. A role grants specific actions on defined resources down to the collection level. Self-hosted servers and Atlas clusters use different built-in role lists. Both systems build their roles from the same core set of privilege actions.
The simplest way to block deletes is the built-in read role. This role lets the user run find, listCollections, listIndexes, dbStats, collStats, and changeStream. It applies to all non-system collections in the target database. It leaves out the insert, update, remove, and dropCollection actions by design. If the AI assistant only inspects schemas or checks records, this role works well.
Sometimes an AI agent must add new records or edit existing documents during tests. The built-in readWrite role allows insert and update actions for those tasks. Yet readWrite also includes remove, createCollection, createIndex, dropIndex, and dropCollection. Giving an agent readWrite access means it can still wipe documents or drop collections. To allow writes while blocking deletes, admins define a custom database role. That custom role grants find, insert, and update without remove or dropCollection.
Why static database roles leave operational gaps for AI agents
Native database roles check who logs in at the start of a session. They do not inspect the context of individual commands while they run. A role with update rights can still overwrite fields with blank values. That bad update destroys records without ever calling the remove action. Static roles cannot tell a safe one-document edit from a full-collection wipe.
AI coding tools also inherit whatever local keys sit on a developer machine. If an engineer logs in with full rights, the assistant shares that session. Teams then maintain extra database users and rotate separate keys for every project. Static roles also lack field-level data masking for sensitive records. Query results return raw emails, phone numbers, card numbers, and national IDs to the client.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What to check beyond database roles for AI queries
Safe AI database access needs controls that check every command in flight. Teams should inspect each statement before it reaches the database engine. Blocking drop and delete commands at the wire level stops mistakes across all users. This works even when a developer session uses a broad role.
Teams also need to protect private fields returned by find commands. Data masking rewrites matched fields like emails and card numbers in query results. Adding approval steps for write operations lets a human review changes before they run. Central logs of every prompt and database query also help security teams track agent actions.
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
Does the MongoDB read role stop all delete actions from Amazon Q?
Yes, the built-in read role blocks remove and dropCollection actions on that database. The AI agent can only run read actions like find, listCollections, and collStats.
Can Amazon Q still damage data if remove actions are blocked?
Yes, if the database user has update privileges, the agent can still overwrite documents. An update command that sets fields to null can ruin data without deleting documents.
How do you allow inserts from an AI agent while blocking deletes?
Create a custom MongoDB role that grants only find, insert, and update actions. Do not assign the built-in readWrite role, because it includes remove and dropCollection.
Related guides
In this post