How to Configure Goose MongoDB Prevent Delete
To set up a goose mongodb prevent delete rule, assign a custom database role. This role must omit the remove and dropCollection actions from the agent user. Teams often hook AI agents like Goose straight to a database using admin keys. This fast setup helps engineers test prompts and build features right away. Yet a standard write role lets the agent wipe out whole collections by mistake. One bad prompt can erase customer records in seconds. How a goose mongodb prevent delete role works Mong
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 goose mongodb prevent delete rule, assign a custom database role. This role must omit the remove and dropCollection actions from the agent user.
Teams often hook AI agents like Goose straight to a database using admin keys. This fast setup helps engineers test prompts and build features right away. Yet a standard write role lets the agent wipe out whole collections by mistake. One bad prompt can erase customer records in seconds.
How a goose mongodb prevent delete role works
MongoDB controls access through role-based rules. Each role grants rights to run specific actions on a database or a single collection. Self-hosted servers and cloud clusters use the same base privilege actions to build these roles.
When teams want to stop data loss, they first look at built-in roles. The standard read role lets Goose run find, listCollections, listIndexes, dbStats, collStats, and changeStream actions. It blocks insert, update, remove, and dropCollection commands by default. If Goose only needs to inspect data, this read role works well.
Many workflows require the AI agent to add new records or fix old ones. Teams then switch the user to the built-in readWrite role. That role includes all read actions plus insert, update, createCollection, and createIndex. Still, readWrite also grants remove, dropIndex, and dropCollection rights. Giving readWrite to Goose breaks your safety goal.
To let Goose write data without deleting it, you must build a custom role. You define this role on the target database down to the collection level. You grant find, insert, and update actions while leaving out remove and dropCollection. Goose logs in with this custom user and can no longer delete documents.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native database roles fall short for AI agents
Native database roles check who logs in at the start of a session. They do not inspect what individual commands try to do with the data in flight. Even without the remove action, an agent with update rights can ruin a collection. Goose can run an update command that overwrites every field with blank values.
Static roles also create a problem for secrets management. Goose needs a database user key stored on the local machine to log in. If you want the agent to run one safe delete, you must change the role. You end up maintaining dozens of custom roles across every database.
Read queries bring another risk when AI agents inspect live tables. The read role lets Goose pull full documents from any non-system collection in that database. Those documents often hold emails, phone numbers, card numbers, or national IDs. Native roles cannot rewrite matched fields in results before the agent reads them.
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
Does the MongoDB read role stop Goose from deleting data?
Yes, the built-in read role stops all deletes. It only allows read actions like find and listCollections, and it blocks remove and dropCollection.
Why is the readWrite role risky for Goose?
The readWrite role combines insert and update rights with destructive actions. It lets the agent run remove and dropCollection on any collection in that database.
Can I restrict Goose to a single MongoDB collection?
Yes, MongoDB roles apply to a database and work down to the collection level. You can grant find and insert on one collection while blocking access to others.
Related guides
In this post