How to Fix MongoDB Error 215 (DatabaseDropPending)
The mongodb error 215, named DatabaseDropPending, happens when an operation hits a database that is being deleted. To fix it, wait for the drop task to finish or stop apps from sending new writes. Database drops do not finish right away in large clusters. While the engine cleans up collections and indexes, it blocks new work on that database. If a client app or script tries to read or write during this window, the server returns code 215. What causes mongodb error 215 in a cluster In MongoDB
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.
The mongodb error 215, named DatabaseDropPending, happens when an operation hits a database that is being deleted. To fix it, wait for the drop task to finish or stop apps from sending new writes.
Database drops do not finish right away in large clusters. While the engine cleans up collections and indexes, it blocks new work on that database. If a client app or script tries to read or write during this window, the server returns code 215.
What causes mongodb error 215 in a cluster
In MongoDB, error code 215 maps to the official DatabaseDropPending state. When a user or script starts a database drop, the engine marks the database as pending removal. The server must remove every collection, index, and file on disk before the drop is done.
In a replica set or sharded cluster, this cleanup takes time. Primary nodes and secondary nodes must sync the drop change across the network. If an app keeps sending requests to that database name before the cleanup ends, the engine rejects the work with code 215.
This issue often shows up during test runs or staging resets. A script drops a test database and right away tries to build a new collection with the same name. Because the old drop is still running in the background, the new create request fails.
It also happens when a human operator drops a database while background workers are still active. Those workers keep trying to run queries or updates against the dying target. Each attempt triggers another DatabaseDropPending log entry until the drop finishes or the workers stop.
How to diagnose and fix DatabaseDropPending safely
First, check if a drop command is still active on the cluster. Look at the active operations in the database logs or monitoring view. Wait for the storage engine to finish removing the old data files and metadata.
Second, find out which app or user sent the requests during the drop window. Check your app connection pools and background job queues. Stop any worker processes that are still trying to write to the removed database name.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Third, fix automated scripts that drop and recreate databases back to back. Add a short pause or a check in the deployment script so it waits for the drop to finish. Only start creating new collections or indexes after the old database is gone.
Never try to bypass this error by giving app accounts broad admin rights. Keep using tight role rules for your apps and engineers. Wait for the engine to clear the pending state on its own so replica nodes stay in sync.
How to prevent accidental drops with role rules
Many DatabaseDropPending incidents start when a user or script has too much power and drops the wrong resource. MongoDB controls access through role-based authorization down to the collection level. A role applies to the database where it lives and grants specific sets of actions.
For services that only need to view data, assign the built-in read role. The read role grants access to non-system collections through actions like find, listCollections, and listIndexes. It does not allow insert, update, remove, or dropCollection actions.
When a service must change records, assign the readWrite role instead of full database admin rights. The readWrite role includes read actions plus insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection. Limiting who can drop whole databases stops surprise DatabaseDropPending errors in production.
Also review how engineers run maintenance commands in live clusters. Require peer review before anyone runs destructive tasks on shared databases. Masking sensitive fields like emails, phone numbers, card numbers, and national IDs in query results also keeps routine checks safe.
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, inline in the MongoDB wire protocol. On every command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13, or hold risky commands for approval. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents in memory, and every verdict is logged. See the open-source code on GitHub.
Frequently asked questions
What does MongoDB error code 215 mean?
MongoDB error code 215 is the DatabaseDropPending error. It means the database is in the middle of being deleted and cannot take new operations right now.
How do I clear a DatabaseDropPending state in production?
Pause any apps or scripts that are sending traffic to that database name. Wait for the database engine and replica nodes to finish the background drop task before running new commands.
Can the MongoDB read role trigger a drop operation?
No, the built-in read role only allows viewing data with actions like find, listCollections, and listIndexes. It does not include actions that modify data or drop collections.
Related guides
In this post