How to Fix MongoDB Error 164 (InitialSyncActive)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mongodb error 164 when an operation runs on a node during initial sync. You fix it by waiting for sync completion or routing traffic to ready nodes. The database engine maps code 164 to the InitialSyncActive failure state. During this phase, a new or restored member copies data from an existing member. The node cannot serve normal queries or accept cluster commands while it builds data. Root causes of mongodb error 164 in replica sets A replica set member enters initial sync when it

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 164 when an operation runs on a node during initial sync. You fix it by waiting for sync completion or routing traffic to ready nodes.

The database engine maps code 164 to the InitialSyncActive failure state. During this phase, a new or restored member copies data from an existing member. The node cannot serve normal queries or accept cluster commands while it builds data.

Root causes of mongodb error 164 in replica sets

A replica set member enters initial sync when it joins the cluster with no data. It also enters this state when an operator wipes its storage to fix data drift. While InitialSyncActive is true, the node clones collections and builds indexes from a source node.

Drivers and scripts trigger mongodb error 164 when they target this syncing node directly. Misconfigured connection strings often point to a single host instead of the replica set. If a script connects to the syncing host and runs a command, the database rejects it. Admin tasks like stepdowns or elections on that member also fail with this code.

Network drops and high disk load can stretch the sync time for many hours. If a health check script polls the node and expects query results, it fails. Teams often mistake this state for a hung server and restart the process. Restarting the node forces the initial sync to start over from scratch.

How to diagnose and fix InitialSyncActive safely

To check the sync status, inspect the replica set state from a healthy member. Do not grant full cluster admin rights to every engineer who checks the node. MongoDB grants access through roles that define actions on specific resources. You can scope roles down to a single database or collection level.

For routine app diagnostics, the built-in read role grants safe inspection actions on non-system collections. It allows actions like finding documents, listing collections, listing indexes, and checking collection stats. It blocks data changes like inserts, updates, removes, or dropping collections. Using scoped read roles keeps engineers from running risky state changes during an incident.

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 how your apps and scripts route requests to the database cluster. Update connection settings so apps target the replica set and route reads to primary or secondary nodes. Ready members handle reads and writes while the new member finishes its background sync. Never disable replica set checks or force the syncing node online early.

Preventing repeat sync failures in production

Long sync times increase the window where scripts hit the InitialSyncActive error. Check the disk throughput and network bandwidth between the sync source and the new node. If the source node handles heavy app traffic, sync speed drops. You can schedule member additions during low traffic hours to speed up data cloning.

Audit your monitoring tools and deployment scripts to make sure they respect member states. Health checks should verify process liveness without running data queries on syncing nodes. When engineers run live checks on production data, add data masking to your workflow. Masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in query results.

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

InitialSyncActive is the official name for error code 164 in the database engine. It means a replica set member is copying data and building indexes right now. The node rejects standard reads, writes, and state changes until the sync finishes.

Should I restart a node showing mongodb error 164?

No, you should not restart the database process unless the sync has stalled completely. Stopping the node wipes out its progress and forces the full data copy to restart. Check your server logs first to confirm that collection cloning or index builds are moving forward.

How do I stop my app from hitting syncing nodes?

Use a replica set connection string instead of a direct host connection string. The driver will discover member states and send queries only to ready primary or secondary nodes. Keep syncing hosts out of static load balancer pools until they reach the secondary state.

The query runs. The emails stay hidden.