How to Fix MongoDB Error 94 (NotYetInitialized)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 94 when a replica set node is not initialized yet. You fix this error by running the replica set setup step on your cluster. The database engine uses the name NotYetInitialized for code 94. Until you finish the setup step, the node cannot elect a primary. It also rejects normal read and write requests from your apps. Root causes of mongodb error 94 in replica sets A database node starts in an uninitialized state when you turn on replication. The node knows it belongs to

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 94 when a replica set node is not initialized yet. You fix this error by running the replica set setup step on your cluster.

The database engine uses the name NotYetInitialized for code 94. Until you finish the setup step, the node cannot elect a primary. It also rejects normal read and write requests from your apps.

Root causes of mongodb error 94 in replica sets

A database node starts in an uninitialized state when you turn on replication. The node knows it belongs to a replica set, but it lacks a member list. When a client sends a query or status check, the engine returns code 94.

This issue often happens during fresh cluster builds or automated cloud rollouts. Your deployment script might start the database service and run health checks right away. If those checks run before the replica set setup command finishes, they fail.

You can also hit mongodb error 94 when you add a brand new node. If the new node cannot reach the existing primary over the network, setup stalls. Firewalls, wrong hostnames, or broken DNS records often block this first handshake between nodes.

Disk errors or missing local database files can trigger NotYetInitialized after a restart too. If a node loses its local system data, it forgets the replica set state. It then acts like a fresh node waiting for its first setup instruction.

How to diagnose and fix NotYetInitialized in production

First, check whether this cluster is brand new or an existing production system. Never run a fresh replica set setup command on a broken node with old data. Doing so can create a split brain and cause data loss across the cluster.

For a brand new cluster, log in to one node with an admin role. Run the standard replica set initialization operation once, and wait for the primary election. After a few seconds, the node moves to a normal state and accepts queries.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

For an existing cluster, check your network paths and hostnames between all member nodes. Make sure the primary node can reach the new node on the database port. Use the primary node to add the new member to the existing set.

Keep permissions tight when your team investigates or fixes replica set errors in production. MongoDB grants access through roles that define allowed actions on specific database resources. A role applies to its defined database and works down to the collection level.

Give operators a read role when they only need to check collection stats. The read role allows read access to non-system collections without insert, update, or remove actions. Do not hand out full cluster admin keys for basic status checks.

Preventing replica set startup failures in automated builds

You can stop code 94 in automated builds by ordering your startup tasks well. Wait for all database processes to listen on the network before running setup scripts. Add a short retry loop in your app startup logic to handle brief delays.

Track all admin commands run during cluster setup and repair sessions for audit trails. Also make sure your query tools protect sensitive data once the database goes live. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in 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 NotYetInitialized mean in MongoDB?

NotYetInitialized is the official name for error code 94 in the database engine. It means a node started in replica set mode but lacks a valid member list.

Can I fix mongodb error 94 by restarting the database service?

A simple restart will not fix a brand new replica set that lacks setup. You must initialize the set on a new cluster or sync from an existing primary.

Does fixing error 94 require full readWrite access to all collections?

No, initializing a replica set uses cluster admin actions rather than collection data roles. The readWrite role is for modifying collection data through insert, update, and remove actions.

The query runs. The emails stay hidden.