LESSON 11 / 20·2 min readIntermediate

What do set, addFields, skip and count do?

01 Understand02 Recall03 Prepare

Understand the concept

These stages shape or limit pipeline output: $set/$addFields create or replace fields, $skip removes a leading number of results, and $count summarizes how many documents remain. Their position determines whether they operate on source records or already transformed results. A small final result does not mean the earlier work was small.

Important ideas

  • $set and $addFields add or replace fields.

  • $skip discards the first N results; deep offsets can be slow.

  • $count returns the number of documents reaching that stage.

  • Place a deterministic $sort before page boundaries when results must be stable across requests.

PAUSE & RECALL

Can you explain it without the notes?

What do set, addFields, skip and count do?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

These stages shape or limit pipeline output: $set/$addFields create or replace fields, $skip removes a leading number of results, and $count summarizes how many documents remain. Their position determines whether they operate on source records or already transformed results. A small final result does not mean the earlier work was small.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • $skip still requires advancing past earlier results, which is why deep offset pagination can become expensive.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: When do I need a transaction?

Adapted from 04_MONGODB_MONGOOSE.md · “What do set, addFields, skip and count do?”. Examples are study fragments; framework behavior can depend on your version.