How to Fix MongoDB Error 65 (MultipleErrorsOccurred)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 65 when a single command triggers more than one failure. You fix it by reading the full error array and fixing each sub-error. The database engine maps code 65 to the official name MultipleErrorsOccurred. It acts as a wrapper when a batch task hits several problems at once. Instead of hiding extra failures, the server groups them under this main code. Engineers must inspect the inner error list to find the true cause. What causes mongodb error 65 in your database Batch

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 65 when a single command triggers more than one failure. You fix it by reading the full error array and fixing each sub-error.

The database engine maps code 65 to the official name MultipleErrorsOccurred. It acts as a wrapper when a batch task hits several problems at once. Instead of hiding extra failures, the server groups them under this main code. Engineers must inspect the inner error list to find the true cause.

What causes mongodb error 65 in your database

Batch writes and bulk tasks are the most common triggers for this error. A client app might send hundreds of new records in one request. If three records break unique key rules, the server notes all three failures. It then returns code 65 to tell the app that several problems happened.

Cluster operations across many shards also produce this error code in production. A query or index build might run on four shards at the same time. If two shards drop their network links or run out of disk space, both fail. The router collects these shard errors and wraps them into a single response.

Schema checks and role limits can also play a part in bulk failures. MongoDB grants access through role-based rules that apply to a specific database. A role can grant access down to a single collection level. If a batch job touches a restricted collection, some actions fail while others pass.

For example, the built-in read role only allows safe actions like find and listCollections. It does not allow insert, update, remove, or dropCollection actions on the database. If an app with the read role sends mixed tasks, the write steps fail. When several write steps fail in one batch, the server can group those errors.

How to diagnose and fix the failure in production

Start by checking the detailed error log from your database driver or server. Never rely on the top-level error code alone when code 65 appears. Look inside the response payload for the child error array and individual error codes. Each item in that array shows the exact document index and failure reason.

MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Separate data errors from system errors before you retry any failed batch job. If the inner errors show duplicate keys, fix the bad records in your app. Retrying bad data without changes will only trigger the exact same error again. If the inner errors show network timeouts, check your shard health and node load.

Check the user roles if the inner errors point to missing write permissions. The readWrite role includes all read actions plus insert, update, and remove rights. It also allows createCollection, createIndex, dropIndex, and dropCollection on that database. Grant only the exact role needed on the target collection instead of wide admin rights.

Keep your production data safe while you inspect failed records in the logs. Batch error logs often print the raw fields of the documents that failed. If those documents hold emails, phone numbers, card numbers, or national IDs, logs expose them. Data masking rewrites matched fields in results so debug logs stay safe during fixes.

How to prevent batch failures in future runs

Break huge bulk jobs into smaller batches to make error recovery much easier. Smaller batches put less stress on shard memory and network links during peak hours. They also keep the error array short and easy to read when failures happen.

Use unordered batch writes when one bad record should not stop the whole job. With unordered writes, the engine processes all valid records and lists the failed ones. Your app can then read the error list and fix only the broken items. Test your batch schemas in a staging setup before running big jobs in production.

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 error code 65 mean in MongoDB?

Code 65 means MultipleErrorsOccurred during a single database command or batch request. The server uses it to wrap a list of smaller errors into one response.

Does error 65 roll back all changes in a batch?

No, standard bulk writes do not roll back changes that already succeeded before the error. Only multi-document transactions undo all steps when a batch hits multiple errors.

How do I find the real cause behind code 65?

Read the nested writeErrors or child error details inside the server response object. Each entry lists the specific error code and message for every failed sub-task.

The query runs. The emails stay hidden.