issue 117apr 27mmxxvi
est. 2017
Sun, 27 Apr 2026
vol. IX · no. 117
PapersAdda
placement intelligence, since 2017
640+ briefs · 24 campuses · by reservation
verified offers · sourced from r/developersIndia
razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1

MongoDB Aggregation Interview Questions 2026, 28 Pipeline Q&A with Queries

9 min read
Interview Questions
Updated: 8 Jun 2026
Aditya Sharma
Aditya's Edit

PapersAdda 2026 Placement Cycle

By Aditya Sharma·Founder & Editor, PapersAdda

What changed in 2026 drives

Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.

What I'd actually study for this

  • 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
  • 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
  • 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
  • 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken

Where most candidates trip up

The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.

Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.

The aggregation pipeline is where MongoDB interviews separate users from experts. Candidates report that one well-posed pipeline question, "compute revenue per customer with their latest order", filters who has actually done analytics on MongoDB. This guide compiles 28 questions from candidate-reported rounds and public preparation resources, each with a runnable pipeline and the optimization the interviewer is probing.

The model: documents flow stage to stage like a Unix pipe. Each stage transforms the stream. Order stages to filter early and compute late.

Related: MongoDB Interview Questions 2026 | Node.js Interview Questions 2026 | MySQL Interview Questions 2026 | PostgreSQL Interview Questions 2026


Core Stages (Q1 to Q12)

Q1. What is the aggregation pipeline?

Q2. What does $match do and why place it first?

db.orders.aggregate([{ $match: { status: 'paid', amount: { $gt: 100 } } }]);

Q3. What does $group do?

db.orders.aggregate([
  { $group: { _id: '$userId', total: { $sum: '$amount' }, count: { $sum: 1 } } }
]);

Q4. What are the common accumulator operators?

AccumulatorResult
$sumTotal (use $sum: 1 to count)
$avgAverage
$min / $maxExtremes
$first / $lastFirst/last in group (needs $sort)
$pushArray of values
$addToSetArray of unique values

Q5. What does $project do?

{ $project: { name: 1, year: { $year: '$createdAt' }, _id: 0 } }

Q6. What does $sort do and how do you optimize it?

Q7. What is $limit and $skip?

Q8. What does $unwind do?

db.orders.aggregate([{ $unwind: '$items' }, { $group: { _id: '$items.sku', qty: { $sum: '$items.qty' } } }]);

Q9. What does $lookup do?

{ $lookup: { from: 'users', localField: 'userId', foreignField: '_id', as: 'user' } }

Q10. How do you flatten a $lookup result?

Q11. What does $addFields do?

Q12. What is $count?


Intermediate Pipelines (Q13 to Q22)

Q13. How do you compute revenue per customer with their name?

db.orders.aggregate([
  { $match: { status: 'paid' } },
  { $group: { _id: '$userId', revenue: { $sum: '$amount' } } },
  { $lookup: { from: 'users', localField: '_id', foreignField: '_id', as: 'user' } },
  { $unwind: '$user' },
  { $project: { _id: 0, name: '$user.name', revenue: 1 } },
  { $sort: { revenue: -1 } }
]);

Candidate-reported as a near-canonical aggregation question. The interviewer watches stage order: filter, group, join, flatten, shape, sort.

Q14. How do you get the latest order per user?

db.orders.aggregate([
  { $sort: { userId: 1, createdAt: -1 } },
  { $group: { _id: '$userId', latest: { $first: '$$ROOT' } } }
]);

$first after a sort captures the newest. $$ROOT refers to the whole document.

Q15. What is $facet and when do you use it?

{ $facet: { byStatus: [{ $group: { _id: '$status', n: { $sum: 1 } } }], total: [{ $count: 'all' }] } }

Q16. What is $bucket and $bucketAuto?

Q17. How do conditional expressions work in aggregation?

{ $project: { tier: { $cond: [{ $gt: ['$amount', 1000] }, 'gold', 'standard'] } } }

Q18. How do you handle dates in aggregation?

{ $group: { _id: { $dateToString: { format: '%Y-%m', date: '$createdAt' } }, total: { $sum: '$amount' } } }

Q19. What are aggregation window functions?

Q20. How do you deduplicate documents in a pipeline?

{ $group: { _id: '$email', doc: { $first: '$$ROOT' } } },
{ $replaceRoot: { newRoot: '$doc' } }

Q21. What does $replaceRoot do?

Q22. How do you write results to a collection?


Performance and Scenarios (Q23 to Q28)

Q23. What is the memory limit for a stage and how do you handle it?

Q24. How do you make an aggregation use an index?

Q25. Why is $lookup sometimes slow and how do you speed it up?

Q26. Scenario: a dashboard query times out. How do you optimize the pipeline?

Q27. How do you debug a wrong aggregation result?

Q28. When should you precompute aggregations instead of running them live?


Aggregation Mock Test, 2026 Edition

5 original questions calibrated to the 2026 MongoDB batch by Aditya Sharma, from candidate-reported patterns.

Question 1

To count documents per group you use:

a) $count inside $group b) $sum: 1 in $group c) $size d) $limit

Solution: { $sum: 1 } counts documents per bucket. Answer: (b)

Question 2

$match should be placed:

a) last b) as early as possible to shrink the set and use indexes c) after $group d) anywhere

Solution: Early filtering reduces work and enables index use. Answer: (b)

Question 3

$unwind on an array field:

a) deletes the array b) outputs one document per array element c) sorts the array d) sums it

Solution: It deconstructs the array into separate documents. Answer: (b)

Question 4

The default per-stage memory limit is:

a) 16 MB b) 100 MB c) unlimited d) 1 GB

Solution: 100 MB per stage unless allowDiskUse is set. Answer: (b)

Question 5

To run several aggregations on the same input in one query, use:

a) $group b) $facet c) $project d) $merge

Solution: $facet runs parallel sub-pipelines. Answer: (b)


FAQ, MongoDB Aggregation Questions

Q: How many aggregation questions appear in a round? Candidates report one to three, usually one substantial pipeline you write live.

Q: Do freshers get aggregation questions? Lightly, basic $match plus $group. Deeper $lookup, $facet, and window functions skew mid to senior.

Q: Is aggregation faster than application-side processing? Usually yes, the database is closer to the data, but only with proper indexes and early filtering. Confirm operator behavior on the official MongoDB docs.

Q: What is the most-missed aggregation mistake? Forgetting that $unwind multiplies documents and inflates later sums, per candidate-reported feedback.


You May Also Like

Methodology applied to this articlelast verified 8 Jun 2026
Sources used
Public exam-pattern documents, official recruiter pages, and verified candidate reports on r/developersIndia and LinkedIn.
Verification window
Page last edited 8 Jun 2026 by Aditya Sharma. Numbers and patterns sanity-checked against the most recent 2026 cycle drives we tracked.
What we did NOT do
  • No fabricated salary numbers or success rates. If we quote a range, it's sourced.
  • No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
  • No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Verification policy: /editorial-standards/. Found something incorrect? Submit a correction - we respond within 48 hours.

Explore this topic cluster

More resources in Interview Questions

Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.

Paid contributor programme

Sat this this year? Share your story, earn ₹500.

First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.

Submit your story →

Ready to practice?

Take a free timed mock test

Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.

Start Free Mock Test →

Related Articles

More from PapersAdda

Share this guide: