MongoDB & MongooseInterview preparation
Intermediate·Concept·2 min read

What do set, addFields, skip and count do?

Practice this question

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:

  • $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.

Interview point:

  • $skip still 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.