Skip to content
Learn Netverks

Lesson

Step 31/36 86% through track

replication-preview-mongodb

Replication preview

Last reviewed Jun 1, 2026 Content v20260601
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
advanced

This lesson

This lesson teaches Replication preview: document modeling, query operators, and aggregation patterns for MongoDB.

HA and scale change ops—elections, lag, and shard keys show up in senior backend interviews.

You will apply Replication preview in contexts like: Managed Atlas clusters, multi-region apps, and read scaling for analytics replicas.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now.

When find, operators, and basic aggregation pipelines feel familiar in mongosh.

A replica set is primary + secondaries for redundancy and read scaling. Oplog replays operations to secondaries.

Roles

  • Primary — accepts writes
  • Secondary — replicates, can serve reads with readPreference
  • Arbiter — voting only, no data (legacy layouts)

Read preference

// Driver concept:
// readPreference: 'secondaryPreferred' for analytics reads

Practice: Concepts apply to Atlas and self-hosted; try read-only commands in mongosh where safe.

Failover

Election picks new primary on failure—apps must handle brief write errors and retry.

Change streams (on replica sets)

const cs = db.orders.watch()
// Apps consume insert/update/delete events; store resume tokens after restarts

Change streams tail the oplog—use for cache invalidation, search sync, or integrations instead of polling updatedAt.

Practice: Concepts apply to Atlas and self-hosted; try read-only commands in mongosh where safe.

Important interview questions and answers

  1. Q: Oplog?
    A: Capped collection of operations secondaries tail for replication.
  2. Q: Change streams vs polling?
    A: Lower latency event delivery with resume tokens vs repeated find queries.

Self-check

  1. Which node accepts writes?
  2. Why store a resume token?

Tip: readPreference secondary for analytics; primary for read-your-writes. Persist change-stream resume tokens.

Interview prep

Primary role?
Accepts writes; secondaries replicate oplog.
readPreference?
Chooses which member serves reads.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • readPreference?
  • Change streams?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump