Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardMongoDBmongos query routingSingle-choice MCQ

An aggregation pipeline on a sharded collection ends with a `$merge` (or `$out`) stage that writes into another sharded collection. After the per-shard sub-pipelines run, where is the `$merge`/`$out` stage executed in the cluster, and why?

db.events.aggregate([ { $match: { day: "2026-06-15" } }, { $group: { _id: "$userId", n: { $sum: 1 } } }, { $merge: { into: "daily_counts" } } ])