How to Fix MongoDB Error 11 (UserNotFound)
You get mongodb error 11 when the database cannot find the requested user account. To fix this UserNotFound error, point your client to the right database or create the user. This failure often happens during login or when an admin tries to update a user. A user account in MongoDB always belongs to one specific database. If you check the wrong database, the engine returns code 11 right away. What causes mongodb error 11 in your cluster The official name for code 11 is UserNotFound. MongoDB s
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 11 when the database cannot find the requested user account. To fix this UserNotFound error, point your client to the right database or create the user.
This failure often happens during login or when an admin tries to update a user. A user account in MongoDB always belongs to one specific database. If you check the wrong database, the engine returns code 11 right away.
What causes mongodb error 11 in your cluster
The official name for code 11 is UserNotFound. MongoDB stores each user record inside a single database that acts as a home for that user. When an app logs in, it must name both the user and that home database. If the app names the wrong database, the server looks in the wrong place. It will not find the user, so it throws this error.
Typos in the username also trigger this exact same code. A missing letter or wrong case will cause the lookup to fail. The database treats a misspelled name as a user that does not exist.
Cluster sync issues or failed deploy scripts can cause this problem too. For example, a setup script might fail before it creates the new app user. Then the app starts up and tries to log in with that missing user. You also see this error when you run a command to drop or edit a missing user.
How to diagnose and fix UserNotFound in production
First, check the login settings in your app or client tool. Look at the database name that the client uses to log in. Many teams put all user accounts in one central admin database. Make sure your client points to that exact database when it sends the login request.
Next, log in with an admin account that can view user records. List the users in the target database and check the exact spelling of each name. If the user is not there, check the other databases on the server. People often create a user in a test database by mistake.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If the user does not exist anywhere, you must create the account in the right database. Keep safety in mind when you set up the new user. MongoDB 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.
Do not give admin powers to fix a simple login issue. Pick the smallest role that lets the user or app do its job. If the user only needs to view data, assign the built-in read role. The read role lets a user find data and list collections or indexes. It blocks actions that change data, like insert, update, remove, or drop collection.
If the app must change records, assign the readWrite role on that database instead. This role adds the power to insert, update, and remove data. Note that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both systems build their roles from the same basic actions.
How to prevent user lookup errors across teams
You can avoid future errors if you standardize where you store user accounts. Pick one database for user logins and write this rule down for your team. When everyone uses the same setup, apps will not look in the wrong place.
You should also cut down the number of manual accounts you manage by hand. When engineers share database logins or create accounts by hand, typos happen often. Move toward central access controls that map team members to the right database roles. Also, test your masking rules so that tools rewrite emails or phone numbers 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 MongoDB error code 11 mean?
Error code 11 means UserNotFound in MongoDB. The database engine could not find the user account in the database you named during login or management.
Why do I get UserNotFound when the user exists?
You are likely pointing your login request to the wrong database. Check where the user was created and make sure your client specifies that exact database for login.
Which role should I give a new user after fixing error 11?
Give the user the smallest role needed for their task on that database. Use the read role for viewing data, or use the readWrite role if the app must change data.
Related guides
In this post