You’ve got a Mongo replica set serving a multi-tenant SaaS workload. Once a week, the data team runs a 90-minute aggregation across the largest collection, and every time it runs you see a P95 spike on the application tier — secondaries are now competing with production reads for wiredTiger cache, and the application’s read preference is picking the busy secondary half the time. The fix isn’t to throw cache at the existing nodes; it’s to add a fourth member that the driver never sees, and route the heavy work there.
What’s happening
MongoDB lets a replica-set member be marked hidden: true. A hidden member receives all replication traffic, holds an up-to-date copy of the data, but is invisible to the driver — db.isMaster() from a client connection will not list it. The driver cannot select it for reads or writes. You then connect to it explicitly by host, bypassing the replica-set abstraction, when you specifically want to read from it.
You also set priority: 0 and votes: 0 on a hidden member that exists for analytics or backups:
priority: 0prevents the member from becoming primary. You don’t want production write traffic ever landing on a host that’s busy with a 90-minute aggregation. A primary-promotion event on the analytics node would be a disaster.votes: 0removes it from elections. Withvotes: 0, the member doesn’t participate in the majority calculation, so adding the hidden node to a PSS replica set keeps the election quorum at 3 voters and majority at 2. Withoutvotes: 0, you’d shift majority to 3-of-4, which is more brittle.
The result is a fourth (or fifth) node that gets data via the same oplog stream, but is fully isolated from production read paths and election timing.
How to verify
Membership and flags:
rs.conf().members.forEach(m => print(
`${m.host} hidden=${m.hidden} priority=${m.priority} votes=${m.votes}`
));
// mongo01.internal:27017 hidden=false priority=2 votes=1
// mongo02.internal:27017 hidden=false priority=1 votes=1
// mongo03.internal:27017 hidden=false priority=1 votes=1
// mongo-analytics.internal:27017 hidden=true priority=0 votes=0
Confirm the driver does not see it from a normal connection:
mongosh --tls --tlsCAFile /etc/mongo/tls/ca.pem \
--tlsCertificateKeyFile /etc/mongo/tls/client.pem \
--host mongo01.internal --eval "db.isMaster()" | jq '.hosts'
# [
# "mongo01.internal:27017",
# "mongo02.internal:27017",
# "mongo03.internal:27017"
# ]
The hidden member should not appear in .hosts. It will appear in .passives if it’s a priority-0 voting member, but with votes: 0 and hidden: true it appears in neither — the driver has no way to discover it.
Verify replication lag from the hidden member, since it’s the one most likely to fall behind under analytics load:
// Connect directly to the hidden member
db.printSecondaryReplicationInfo()
// source: mongo01.internal:27017
// syncedTo: <timestamp>
// 2 secs behind the primary
A lag of seconds is fine; lag growing into minutes means the analytics workload is overwhelming the hidden node and you need to size it up or scope down the queries.
The fix
Add the hidden member to an existing replica set. Provision the host the same way as any other replica-set member (same TLS, same keyFile, same mongod.conf), then add it from a primary:
rs.add({
host: "mongo-analytics.internal:27017",
priority: 0,
votes: 0,
hidden: true,
// For backup-only nodes, optionally also set:
// slaveDelay: 3600 // (mongo <5.0) — held one hour behind
// secondaryDelaySecs: 3600 // (mongo 5.0+)
});
Wait for the initial sync to complete — rs.status() shows stateStr: SECONDARY and 0 lag — before pointing any workload at it.
Then connect your analytics worker explicitly to the host:
// In the analytics worker — connection string targets the hidden member directly
const client = new MongoClient(
"mongodb://mongo-analytics.internal:27017/?tls=true&tlsCAFile=/etc/mongo/tls/ca.pem&directConnection=true",
{ readPreference: "primaryPreferred" } // doesn't matter, it's direct
);
directConnection=true is essential — without it, the driver discovers other members via the replica-set protocol and may route reads back to a visible secondary.
For backup workloads, run mongodump against the hidden member, never against a production-facing secondary:
mongodump \
--uri="mongodb://backup_user:CHANGE_ME@mongo-analytics.internal:27017/?tls=true&directConnection=true" \
--tlsCAFile=/etc/mongo/tls/ca.pem \
--tlsCertificateKeyFile=/etc/mongo/tls/backup.pem \
--archive=/backup/mongo-$(date +%Y%m%d-%H%M%S).archive.gz --gzip \
--readPreference=secondary
A few operational caveats:
- Watch the hidden member’s oplog lag during heavy analytics. A long-running aggregation can keep the hidden secondary busy enough that replication falls behind. If lag grows past 5 minutes, either downsize the query or move it to a dedicated time window.
- Hidden ≠ free. The hidden member receives the full oplog stream — it’s a full data-bearing replica. You pay for its disk and CPU just like any other secondary.
- Two hidden members for redundancy if the analytics workload is business-critical. One hidden node is fine for backups (you can always go to a snapshot), but two is the answer for analytics that must keep running through a node failure.
- Don’t put writes here.
priority: 0prevents primary promotion, but the driver isn’t going to write here anyway. If you ever find yourself thinking about writing to the hidden node, you’ve drifted from the pattern.
For backup-only nodes, consider a delayed hidden member (secondaryDelaySecs: 3600) — replays the oplog with a one-hour lag, giving you a window to recover from a logical-corruption event (a bad UPDATE that replicates instantly) by simply reading the data as it existed an hour ago.
Stack Harbor sets up hidden analytics and delayed-backup members as part of Managed Cloud Ops — with oplog-lag alerts so you find out before the data team does. Talk to us if you want a topology review.