What do set, addFields, skip and count do?
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
-
$setand$addFieldsadd or replace fields. -
$skipdiscards the first N results; deep offsets can be slow. -
$countreturns the number of documents reaching that stage. -
Place a deterministic
$sortbefore page boundaries when results must be stable across requests.
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.
Turn this concept into a clear answer.
$skipstill requires advancing past earlier results, which is why deep offset pagination can become expensive.
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.