How to Fix MongoDB Error 365 (TemporarilyUnavailable)
You get mongodb error 365 when the database returns the TemporarilyUnavailable status during an operation. You fix it by lowering cluster load, waiting for maintenance to finish, and adding backoff retries. This status tells your client app that the target node cannot process the request right now. The database has not lost your data, and the node is not dead for good. Instead, a short spike in work or a cluster state change is blocking the request. What causes mongodb error 365 in your clust
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 get mongodb error 365 when the database returns the TemporarilyUnavailable status during an operation. You fix it by lowering cluster load, waiting for maintenance to finish, and adding backoff retries.
This status tells your client app that the target node cannot process the request right now. The database has not lost your data, and the node is not dead for good. Instead, a short spike in work or a cluster state change is blocking the request.
What causes mongodb error 365 in your cluster
MongoDB maps code 365 to the official error name TemporarilyUnavailable in the server engine. The server sends this code when a subsystem or resource is busy or locked for a short time. Your app asks for an action, and the engine rejects it so the node stays stable.
High write traffic is a common trigger for this error on busy database nodes. When storage queues fill up, the engine sheds extra work instead of crashing the whole host. Background index builds or large data moves between shards can also pauses normal requests for a moment.
Replica set elections and node failovers also cause brief windows where requests cannot finish. During a state transition, a node might pause reads or writes until it settles into its new role. Network hiccups between cluster members can stretch these pauses and trigger code 365 for client apps.
How to diagnose the failure safely in production
When an outage hits, engineers often rush to log in with full admin accounts to check the cluster. Giving out broad write roles during an incident creates huge risk for your production data. A tired responder can run a bad command and drop a collection by mistake.
MongoDB grants access through roles that define which actions a user can run on a resource. A role applies to its home database and can grant access down to a single collection. Note that MongoDB Atlas users have different built-in roles than self-hosted users, though both use the same privilege actions.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
For diagnosis, give responders the built-in read role rather than a role that modifies data. The read role lets a user check non-system collections using find, listCollections, listIndexes, dbStats, and collStats. It leaves out insert, update, remove, and dropCollection, so an engineer can check load safely.
If a responder needs to fix data or drop a bad index, require a peer review first. The readWrite role includes everything in read plus insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection. Also make sure your tools mask sensitive fields like emails, phone numbers, card numbers, and national IDs in query results.
How to fix TemporarilyUnavailable errors and stop repeats
Start by checking your database stats and server logs to see which resource hit its limit. Look for long-running queries or heavy batch jobs that started right before the error 365 spike. If a batch script is flooding the primary node, pause the script or lower its batch size.
Next, check how your client app handles code 365 when the database sends it back. Because TemporarilyUnavailable is a transient error, your app should not fail right away on the first error. Add retry logic with exponential backoff and random jitter so clients wait a bit before trying again.
Jitter stops all your app servers from hitting the recovering database node at the exact same millisecond. If every client retries at once, you create a retry storm that keeps the node stuck. Spread out your heavy cron jobs and move analytic reads to secondary nodes to keep primary load low.
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
What does MongoDB error code 365 mean?
MongoDB error code 365 means TemporarilyUnavailable in the official database error spec. It shows that the database node is too busy or in a transitional state to run your request right now.
Is it safe for my app to retry after mongodb error 365?
Yes, retrying is the right way to handle a TemporarilyUnavailable response from the server. Use exponential backoff and jitter in your retry loop so your app gives the cluster time to recover.
Which MongoDB role should engineers use to inspect error 365 in production?
Engineers should start with the built-in read role, which grants dbStats, collStats, listIndexes, and find actions. This lets the team check collection stats and query patterns without the risk of running update, remove, or dropCollection.
Related guides
In this post