How to Fix MongoDB Error 35 (UserModificationFailed)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 35 when the database fails to update a user account. Fix this UserModificationFailed error by checking role names, target databases, and admin permissions. Database teams run into this block during routine user updates or role changes. The engine stops the change to keep its internal user records safe and valid. Understanding why the database rejects the change helps you fix it fast. What causes mongodb error 35 in your database The official name for this failure is Use

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 35 when the database fails to update a user account. Fix this UserModificationFailed error by checking role names, target databases, and admin permissions.

Database teams run into this block during routine user updates or role changes. The engine stops the change to keep its internal user records safe and valid. Understanding why the database rejects the change helps you fix it fast.

What causes mongodb error 35 in your database

The official name for this failure is UserModificationFailed, and it carries code 35. It happens when a command to change a user account cannot finish its work. Several root causes in the engine or client request can trigger this failure.

First, you might try to assign a role that does not exist yet. MongoDB uses role-based rules to grant actions on specific resources. A role applies to the database where you define it. It can grant access down to the collection level. If you point to the wrong database for a role, the update fails.

Second, the account running the update might lack the right privileges. Standard data roles do not let you change user records. For example, the read role only lets users view non-system collections. It allows actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. The readWrite role adds data changes like insert, update, remove, and dropCollection. Neither of these roles allows user account changes.

Third, deployment differences can cause role mismatches during automated scripts. MongoDB Atlas database users have different built-in roles than self-hosted deployment users. Both setups build roles from the same set of privilege actions. Still, a script written for a self-hosted cluster may fail on Atlas. When the engine sees an invalid role name, it returns code 35.

Finally, cluster state problems can block writes to the internal user collection. If the primary node steps down mid-request, the user update cannot save. Replica set lag or write concern timeouts also trigger this exact error code.

How to diagnose and fix user modification failures safely

Start by reading the full error log message from the database server. Code 35 is a broad wrapper, and the text shows the exact reason. Check the log to see if a role is missing or blocked.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, check the exact database where the target user account lives. Every user in MongoDB belongs to one specific database for login checks. If you run the update against the wrong database, the change will fail. Make sure your session points to the right database before retrying.

Verify the roles you are trying to add or remove from the user. List the existing roles in that database to confirm the exact spelling. Check whether you are working on Atlas or a self-hosted server. Match your requested role names to the built-in roles for that deployment type.

Do not fix permission errors by giving everyone full admin rights. Granting broad admin roles to fix a failed script creates huge security risks. Instead, keep user administration separate from daily data work. Give your automation tool only the specific user management actions it needs. Assign data roles like read or readWrite only to the collections required.

If the roles and permissions look right, check the health of your cluster. Ensure the primary node is stable and can accept writes to system collections. Once the cluster is healthy and the role names match, rerun the update.

How to prevent user update errors in production

Manual user changes often lead to typos and broken role assignments. Teams can avoid these mistakes by reducing how often they alter database users. Instead of updating individual accounts every day, use stable role groups.

Test all user management scripts in a staging setup that matches production. Make sure staging uses the same deployment type as your live database. Keep your role definitions simple and document which database owns each custom role. When you standardize how teams access data, user modification errors drop fast.

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

UserModificationFailed is the official name for error code 35 in MongoDB. It means the database could not complete a request to change an existing user account, its password, or its assigned roles.

Can a user with the readWrite role modify other database users?

No, the readWrite role only grants actions to read and change data in non-system collections, such as insert, update, remove, and createIndex. It does not grant permission to modify user accounts or roles.

Why does my user update script work locally but fail with code 35 in Atlas?

MongoDB Atlas database users have different built-in roles than self-hosted deployment users. If your script tries to assign a self-hosted role name on Atlas, the update fails with code 35.

The query runs. The emails stay hidden.