How to Fix MongoDB Error 149 (NoConfigPrimary)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 149 when a sharded cluster loses its config server primary. To fix this NoConfigPrimary failure, restore quorum and network health across your config servers. Sharded clusters keep cluster metadata on a special replica set of config servers. When this replica set has no primary, the cluster cannot change chunk locations. Apps may still read cached routes, but metadata updates will fail right away. What causes mongodb error 149 in a sharded cluster The official database

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 149 when a sharded cluster loses its config server primary. To fix this NoConfigPrimary failure, restore quorum and network health across your config servers.

Sharded clusters keep cluster metadata on a special replica set of config servers. When this replica set has no primary, the cluster cannot change chunk locations. Apps may still read cached routes, but metadata updates will fail right away.

What causes mongodb error 149 in a sharded cluster

The official database name for code 149 is NoConfigPrimary. It means the router or shard cannot reach a writable config server primary. Several common system issues can trigger this state in a live cluster.

First, network splits can block heartbeats between your config server nodes. If a majority of nodes cannot talk, the primary steps down. No new primary can win an election until the network heals.

Second, host crashes or disk full events can stop the config server processes. A three-node replica set needs at least two healthy members to elect a primary. Losing two nodes at once triggers code 149 across the whole cluster.

Third, heavy load or slow disks on config servers can cause election timeouts. When disk writes stall, nodes miss their heartbeat windows and start new elections. During an election window, the cluster has no primary and returns error 149.

How to find and fix NoConfigPrimary in production

Start by checking the health of every host in the config server replica set. Verify that the database process is running on each config server host. Check disk space, memory usage, and CPU wait times on those machines.

Next, test network paths between the routers, the shards, and the config servers. Firewall rules or DNS failures often block traffic on the config server ports. Fix any broken routes so all nodes can exchange heartbeats again.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Then inspect the replica set status on the surviving config server nodes. Look for members stuck in recovering, startup, or unreachable states. If a node stopped because of a full disk, clear old logs first. Restart the stopped database service so the replica set regains a voting majority.

Once a majority of config servers are online, they will elect a primary. Wait a few seconds for the routers to detect the new primary node. Test a metadata check from a router to confirm that error 149 is gone.

Keeping access safe during cluster recovery

During an outage, engineers often ask for broad admin rights to fix nodes. Sharing root keys in chat rooms creates big security risks for your team. Instead, give responders only the exact permissions they need for the task.

MongoDB uses role-based rules to grant actions on specific database resources. A role applies to its defined database and works down to the collection level. Self-hosted clusters and cloud clusters build their roles from the same privilege actions.

For initial checks, engineers do not need write rights on app data. The built-in read role grants read access to all non-system collections. It allows safe check actions like viewing collection stats and database stats. It leaves out write actions like insert, update, remove, or drop collection.

Reserve write roles and cluster admin rights for the final repair steps. Require peer approval before anyone runs state changes on config servers. Also mask sensitive fields like emails, phone numbers, card numbers, and national IDs. Masking rewrites matched fields in query results during live incident checks.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

What does the NoConfigPrimary error mean in MongoDB?

NoConfigPrimary is the official name for error code 149 in a sharded cluster. It means the config server replica set has no active primary node right now.

Can apps still read data during mongodb error 149?

Yes, routers can still serve reads and writes using cached routing tables. Still, chunk splits, balancer moves, and new collection setups will fail until fixed.

How many config servers need to be up to clear error 149?

A standard three-node config server replica set needs at least two healthy nodes. Once two nodes can talk to each other, they will elect a primary.

The query runs. The emails stay hidden.