How to Fix MongoDB Error 91 (ShutdownInProgress)
You see mongodb error 91 when a database node is shutting down. You fix it by retrying the request on a healthy replica node. The official database spec names this code ShutdownInProgress. It belongs to three groups: ShutdownError, CancellationError, and RetriableError. When a server stops, it cancels active work and blocks new tasks. Apps that use good retry logic handle this event with little trouble. What causes mongodb error 91 in production A database node throws mongodb error 91 during
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 see mongodb error 91 when a database node is shutting down. You fix it by retrying the request on a healthy replica node.
The official database spec names this code ShutdownInProgress. It belongs to three groups: ShutdownError, CancellationError, and RetriableError. When a server stops, it cancels active work and blocks new tasks. Apps that use good retry logic handle this event with little trouble.
What causes mongodb error 91 in production
A database node throws mongodb error 91 during a planned or unplanned stop. Planned stops happen during version upgrades, host reboots, or cloud scaling events. Unplanned stops happen when a host runs out of memory or disk space.
During shutdown, the engine stops taking new reads and writes right away. It also stops queries that are still running and returns this error code. Because the error is in the RetriableError group, client drivers can retry. The driver looks for a new primary node and sends the query again.
Problems start when the cluster has no healthy node to take over. If all nodes reboot at once, the app has nowhere to send work. Old drivers or bad timeout settings can also keep apps stuck on dead nodes. Network tools that hold stale routes can send traffic to a stopping host.
How to check and fix the shutdown safely
Start by checking your cluster status and server logs to find the cause. Look for memory limits, full disks, or planned maintenance jobs on that host. Do not give out full admin rights just to check node health.
MongoDB controls access through roles that grant specific actions on set resources. A role works on its own database down to the collection level. For safe checks, give your team the built-in read role on that database.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The read role lets users run find, listCollections, listIndexes, dbStats, and collStats. It blocks actions that change data, like insert, update, remove, or dropCollection. If an engineer must fix data after a crash, use the readWrite role. The readWrite role adds insert, update, remove, createCollection, createIndex, and dropIndex actions. Note that Atlas users and self-hosted users have different built-in role options. Still, both sets of roles use the same basic privilege actions.
Next, check how your app handles retries when a node goes down. Make sure your client driver turns on retryable reads and retryable writes. When the driver sees a RetriableError, it waits for a replica set election. Once a new primary node steps up, the driver sends the request again.
During a rolling restart, wait for each node to rejoin before stopping the next. Check that the replica set stays healthy at every step of the upgrade. If a host crashed from high memory use, tune your queries or add RAM. Also set up data masking so query results rewrite emails and phone numbers.
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 sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.
Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and 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
Is mongodb error 91 safe to retry in my app?
Yes, the database spec marks code 91 as a RetriableError. Modern drivers will catch this code and send the request to a healthy node.
Does ShutdownInProgress mean my database lost data?
No, it just means the node stopped taking work and canceled running queries. Committed writes stay safe if they reached a majority of replica set nodes.
How can I avoid this error during planned upgrades?
Use rolling restarts so only one node stops at any given time. Step down the primary node cleanly before you stop the server process.
Related guides
In this post