$min and $max Accumulators in MongoDB Aggregation
📖 Scenario: You work at a small bookstore that keeps track of sales in a MongoDB collection. Each sale document records the book title and the number of copies sold. You want to find the minimum and maximum number of copies sold among all sales to understand the range of sales performance.
🎯 Goal: Build a MongoDB aggregation pipeline that uses the $min and $max accumulators to find the smallest and largest number of copies sold in the sales collection.
📋 What You'll Learn
Create a
sales collection with documents containing title and copies_sold fields.Define a variable
pipeline that holds the aggregation pipeline array.Use the
$group stage with $min and $max accumulators on the copies_sold field.Complete the pipeline so it returns a single document with
minCopies and maxCopies fields.💡 Why This Matters
🌍 Real World
Bookstores and many businesses use MongoDB to analyze sales data and find minimum and maximum values to understand performance ranges.
💼 Career
Knowing how to use MongoDB aggregation with accumulators like $min and $max is important for data analysts and backend developers working with NoSQL databases.
Progress0 / 4 steps