Nearby lessons
15 of 22🧮 MongoDB: Arithmetic Operators
MongoDB provides a range of arithmetic operators that allow you to perform mathematical calculations
directly within aggregation pipelines. These operators help in computing totals, differences, percentages,
averages, and other numeric transformations efficiently.
📚 Initial Data Setup — sales Collection
1️⃣ Using $add — Add Values
2️⃣ Using $subtract — Subtract Values
3️⃣ Using $multiply — Multiply Values
4️⃣ Using $divide — Divide Values
5️⃣ Using $mod — Modulus (Remainder)
6️⃣ Using $pow — Exponentiation (price²)
7️⃣ Using $round — Round Result (price / 3)
8️⃣ Using $sqrt — Square Root (√price)
9️⃣ Using $abs — Absolute Value (|price - 200|)
🔟 Using $ceil — Round Up (quantity / 4)
1️⃣1️⃣ Using $floor — Round Down (quantity / 4)
1️⃣2️⃣ Using $trunc — Truncate Value (quantity / 4)
Keep Going!MongoDB - String Operators