What do set, addFields, skip and count do?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn What do set, addFields, skip and count do?
Definition:
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.
Key points:
-
$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.
Interview point:
$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?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.