How to Fix MongoDB Error 285 (IndexBuildAlreadyInProgress)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mongodb error 285 when a client tries to start an index build that is already running. To fix this error, let the current index build finish before you send a new request. MongoDB names this failure IndexBuildAlreadyInProgress under code 285. It protects the database engine from running duplicate work on the same collection at the same time. When teams understand why this collision happens, they can stop deployment scripts from failing in production. Root causes of mongodb error 285 i

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 285 when a client tries to start an index build that is already running. To fix this error, let the current index build finish before you send a new request.

MongoDB names this failure IndexBuildAlreadyInProgress under code 285. It protects the database engine from running duplicate work on the same collection at the same time. When teams understand why this collision happens, they can stop deployment scripts from failing in production.

Root causes of mongodb error 285 in your database

Database engines need strict control over how indexes are built on large collections. Building an index takes disk space, memory, and processor time. If two clients ask for the exact same index at once, the second request triggers code 285.

App deployments are the most common cause of this problem. Many teams run startup scripts that create indexes when an app server boots up. When you deploy ten app instances at once, all ten send index requests together. The first instance starts the build, and the other nine instances receive IndexBuildAlreadyInProgress.

Client timeouts can also trigger this error during heavy workloads. If an index build takes longer than the client timeout, the client drops the connection. The database keeps building the index in the background, even though the client disconnected. If an automation script retries the request right away, the database blocks it with code 285.

Role design also plays a big part in who can trigger this error. MongoDB grants access through roles that allow specific actions on resources down to the collection level. The built-in readWrite role includes actions that modify data, as well as createIndex and dropIndex. If every app instance runs with readWrite privileges, any instance can start a duplicate index build.

How to diagnose and fix IndexBuildAlreadyInProgress safely

Start by checking if an index build is still running on your target collection. You do not need write access to inspect index state in production. The built-in read role grants actions like find, listCollections, listIndexes, dbStats, and collStats on non-system collections. Give your engineers read privileges so they can check collection stats and active indexes safely.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once you confirm a build is running, wait for the database to complete the job. Do not restart the database node or kill the task unless the server is out of disk space. Stopping a build early wastes all the work the engine has already done. After the build finishes, check the collection index list to confirm the new index is ready.

How to prevent duplicate index builds in production

The best way to stop code 285 is to separate schema changes from app startups. App servers should not build indexes every time they boot up in production. Move index creation into a dedicated migration step that runs only once per release. That single job can wait for the build to finish before the new app servers start.

You should also tighten database roles for your daily workloads and users. MongoDB Atlas and self-hosted deployments use different built-in roles, but both use the same privilege actions. Remove the readWrite role from services that only need to query data. When fewer clients hold the createIndex action, accidental index collisions happen much less often.

Finally, update your migration scripts to check existing indexes before starting a build. A script can use the listIndexes action to see if the index is already there. If an index build is already in progress, the script should pause and poll until it finishes. This simple check keeps your deployment pipeline green and protects your database from extra load.

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 IndexBuildAlreadyInProgress mean in MongoDB?

It means the database is already building the index you asked to create. MongoDB returns error code 285 to stop duplicate builds from running at the same time.

Does mongodb error 285 harm my existing collection data?

No, this error does not corrupt or delete any records in your collection. It only rejects the duplicate request while the first index build keeps running in the background.

Which MongoDB role allows a user to create or check indexes?

The built-in readWrite role includes the createIndex and dropIndex actions along with data modification actions. The built-in read role includes the listIndexes action, which lets users check existing indexes safely.

The query runs. The emails stay hidden.