How to Fix MongoDB Error 104 (NodeNotElectable)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mongodb error 104 when a replica set member cannot become the primary node. To fix this NodeNotElectable failure, update the member priority or wait for sync to finish. Replica sets rely on clear voting rules to pick a primary node during a failover. When an operator forces a step up on an ineligible host, the engine blocks it. Understanding why a node cannot win an election helps you restore write operations fast. What causes mongodb error 104 in replica sets The database engine map

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 104 when a replica set member cannot become the primary node. To fix this NodeNotElectable failure, update the member priority or wait for sync to finish.

Replica sets rely on clear voting rules to pick a primary node during a failover. When an operator forces a step up on an ineligible host, the engine blocks it. Understanding why a node cannot win an election helps you restore write operations fast.

What causes mongodb error 104 in replica sets

The database engine maps code 104 to the official NodeNotElectable error name. This error appears when a secondary node cannot take over as the primary member. Several cluster settings or node states can trigger this specific block.

First, the target node might have a priority value set to zero. Zero-priority nodes can hold data copies, but they can never become the primary node. Hidden members and delayed members also must keep a zero priority setting. They serve specific backup or reporting needs and cannot lead the cluster.

Second, an arbiter node never holds cluster data and cannot become primary. If an admin targets an arbiter during a manual election test, the request fails.

Third, the member might still be syncing data or recovering its local state. A node must reach a healthy secondary state before it can seek primary status. Network splits can also isolate a node from the rest of the voting group. Without a majority of online peers, the node will reject election requests.

How to diagnose and fix NodeNotElectable safely

Start by checking the current state of every member in your replica set. You do not need broad write rights to check replica set health. MongoDB grants access through roles that define allowed actions on specific resources. A role applies to a database and can grant access down to one collection.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Give on-call staff a read-only role so they can inspect status without risk. The built-in read role grants actions like find, listCollections, listIndexes, dbStats, and collStats. It blocks actions that change data, such as insert, update, remove, or dropCollection. Note that Atlas database users have different built-in roles than self-hosted deployment users. Both types still build from the same underlying set of privilege actions.

Once you read the cluster state, check two things on the failing host. Look at its current health state and its assigned election priority number. If the node is still building indexes or catching up on oplog entries, wait. The NodeNotElectable error will clear once the member finishes its sync cycle.

If the node is healthy but has zero priority, review your cluster design. Sometimes teams set zero priority on nodes in a remote backup data center. This stops a slow remote host from taking over during a brief network blip. Only raise the node priority if that host should handle live app writes.

How to prevent election failures during maintenance

Many teams hit NodeNotElectable during planned patching or server upgrades. An engineer steps down the current primary, expecting a specific secondary to take over. If all remaining online secondaries have zero priority, the cluster loses its primary.

Before you step down a primary node, check that another electable secondary is ready. Verify that the target secondary has a positive priority and low replication lag. Keep change permissions locked down so engineers do not alter replica rules by mistake. Only grant update rights when a planned cluster change requires them. When results include sensitive fields like emails or card numbers, masking rewrites matched fields in results.

Check MongoDB commands and documents on the wire

MongoDB roles and SCRAM login decide who opens a session. They do not check single commands or redact sensitive fields inside returned documents. With hoop.dev, you run an open-source proxy, a sidecar for your MongoDB, inline in the MongoDB wire protocol. On every command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13, or hold risky commands for approval. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents in memory, and every verdict is logged. See the open-source code on GitHub.

Frequently asked questions

What does the NodeNotElectable error mean in MongoDB?

NodeNotElectable is the official name for mongodb error 104. It means a replica set member cannot become the primary node due to its state or settings.

Can a hidden or delayed replica set member trigger error 104?

Yes, hidden and delayed nodes always have zero priority in the replica set. If you try to force them to become primary, the database returns error 104.

Which permissions do engineers need to check replica set status safely?

Assign least-privilege read roles to inspect database statistics without granting data write actions. Save cluster admin roles for verified maintenance tasks that update replica set rules.

The query runs. The emails stay hidden.