How to Configure GitHub Copilot MongoDB Prevent Delete
You can set up github copilot mongodb prevent delete rules by assigning strict database roles. You also need to restrict the database credentials that your AI coding agent uses. Many teams give their coding assistant a standard developer account for quick testing. This setup is risky when roles have broad permissions across your data collections. An agent might run a script or tool call that wipes out key records. If the database account has full write privileges, the database will allow that re
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 can set up github copilot mongodb prevent delete rules by assigning strict database roles. You also need to restrict the database credentials that your AI coding agent uses. Many teams give their coding assistant a standard developer account for quick testing. This setup is risky when roles have broad permissions across your data collections. An agent might run a script or tool call that wipes out key records. If the database account has full write privileges, the database will allow that removal.
How to set up github copilot mongodb prevent delete
To prevent data loss, you must start with native role-based authorization in your database. A database role grants privileges to perform specific actions on defined resources. Each role applies to the database where you define it. You can grant access down to a single collection level. Notice that Atlas users and self-hosted users have different built-in roles. Still, both types of deployments build roles from the same set of privilege actions.
The simplest way to block deletions is to assign the built-in read role. The read role lets a user read all non-system collections in that database. It allows safe actions like finding documents and listing collections or indexes. It also allows checking database stats, collection stats, and change streams. Importantly, the read role does not include insert, update, remove, or dropCollection actions. When your coding assistant connects with a read role, it cannot delete any documents.
Sometimes an AI agent needs to insert test records or update existing documents. Teams often assign the built-in readWrite role for these tasks. The readWrite role includes everything in the read role plus data modification actions. Still, its actions include remove and dropCollection alongside insert and update. To allow writes while blocking deletes, an admin must create a custom role. That custom role should grant find, insert, and update actions on target collections. It must leave out the remove and dropCollection actions entirely.
Why native roles leave an operational gap
Native database roles solve the basic problem of who can log in. They also define the broad categories of actions a database user can run. Creating a read-only user or a custom role stops outright document removal. Yet static roles create friction during daily development and debugging work. Developers often switch back to a shared readWrite account when they need full privileges. Once that connection string sits in a local file, the AI agent can use it.
MongoDB Authentication & Authorization + GitHub Actions Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static database roles also cannot inspect the context of individual commands in flight. A custom role that allows updates still lets an agent overwrite every document. A bad update filter can blank out fields across an entire collection at once. Native roles cannot require human approval for a single risky query while allowing safe ones. They also do not mask sensitive fields like emails, phone numbers, or card numbers in results. The database simply checks if the user role permits the action type and runs it.
Managing agent tool calls in your editor
You should also review how your coding assistant reaches the database from your editor. AI coding agents typically reach external systems through tool servers or terminal commands. When you set up a database tool server, pass it the restricted user credentials. Never put a database admin password into your workspace settings or local files. You should also keep terminal execution in manual approval mode inside your editor. Manual approval lets you read every shell command or script before the agent runs it. Combining restricted database roles with manual command checks reduces the chance of accidental data loss.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.
Frequently asked questions
Does the built-in read role block all document deletions?
Yes, the built-in read role blocks document deletions and collection drops. It only grants read actions like finding records and viewing collection stats. It excludes the remove and dropCollection privilege actions.
Why is the readWrite role risky for AI coding assistants?
The readWrite role grants full modification powers on the database. Alongside insert and update actions, it includes the remove and dropCollection actions. An agent using a readWrite account can delete records or drop whole collections.
Can I block deletes on just one specific collection?
Yes, native roles can grant access down to the collection level. You can build a custom role that grants find, insert, and update on that collection. Just omit the remove and dropCollection actions from that role definition.
Related guides
In this post