How to Fix MongoDB Error 98 (DBPathInUse)
You see mongodb error 98 when a new database process tries to use a locked data folder. You can fix this DBPathInUse issue by stopping the active process or picking an empty folder. Database engines lock their storage paths to stop two processes from writing to the same files. When two instances write to one folder at once, they ruin the underlying storage files. The database blocks the second startup attempt right away to keep your records safe. Root causes of mongodb error 98 in database sy
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 98 when a new database process tries to use a locked data folder. You can fix this DBPathInUse issue by stopping the active process or picking an empty folder.
Database engines lock their storage paths to stop two processes from writing to the same files. When two instances write to one folder at once, they ruin the underlying storage files. The database blocks the second startup attempt right away to keep your records safe.
Root causes of mongodb error 98 in database systems
The official name for code 98 in this database engine is DBPathInUse. It means the storage path you chose already has an active lock file inside it. One common cause is an old database process that is still running in the background.
An engineer or an automated script might try to start a second instance by mistake. If the new instance points to the same data directory, the engine stops and throws code 98. Another common cause is a sudden server crash or a hard power loss.
When a host machine loses power, the database cannot clean up its lock files before shutting down. When the host boots back up, the startup script sees the leftover lock file and stops. Shared network drives and container volume mounts can also trigger this conflict during a deployment.
If an old container stays alive while a new one starts, both will fight for the same disk. The storage engine steps in and blocks the new container from mounting the data path.
How to check and fix DBPathInUse in live systems
Start by checking if an active database process is already running on the host machine. Look at the system process list to see if the database engine is still active. If you find a running instance that should be off, send it a clean shutdown signal.
Wait for the process to finish writing its data to disk and exit on its own. Never force kill a live database process unless every safe shutdown method has failed. Force killing an active engine can damage your data files and leave the lock file behind.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Never delete a lock file by hand while a database process is still using that folder. If no process is running, check if an uncleared lock remained after a sudden host crash. Once you verify no engine is running, you can let the storage recovery process run on startup.
Preventing path conflicts with safe role setup
Many DBPathInUse errors happen when too many people have host access to restart database services. You should separate host service management from daily data checks by using built-in database roles. This database grants access through role-based rules that apply to the database where you define them.
A role can grant access down to a single collection level of detail. For daily checks, give engineers the built-in read role on the target database. The read role lets users view non-system collections by using find, listCollections, listIndexes, dbStats, and collStats.
It does not allow insert, update, remove, or dropCollection actions, so users cannot alter records. If an app or team member needs to change records, grant the readWrite role instead. The readWrite role includes everything in the read role plus insert, update, remove, createIndex, and dropCollection.
By keeping engineers inside database roles rather than host shells, you stop accidental service restarts. You can also add data masking to rewrite emails, phone numbers, card numbers, and national IDs in query results.
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 the DBPathInUse message mean?
DBPathInUse is the official name for mongodb error 98. It means another process is already using the data folder, or an old lock file is still there.
Can I fix code 98 by deleting the lock file?
Do not delete the lock file while a database process is running, or you will corrupt your data. First verify that all database processes have stopped, then restart the service so it recovers cleanly.
How do built-in roles help reduce service restart errors?
Giving users the read or readWrite role lets them check stats and data without logging into the host. When fewer people run service commands on the server, fewer path lock conflicts happen.
Related guides
In this post