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
Example01
1️⃣ Using $add — Add Values
Example02
2️⃣ Using $subtract — Subtract Values
Example03
3️⃣ Using $multiply — Multiply Values
Example04
4️⃣ Using $divide — Divide Values
Example05
5️⃣ Using $mod — Modulus (Remainder)
Example06
6️⃣ Using $pow — Exponentiation (price²)
Example07
7️⃣ Using $round — Round Result (price / 3)
Example08
8️⃣ Using $sqrt — Square Root (√price)
Example09
9️⃣ Using $abs — Absolute Value (|price - 200|)
Example10
🔟 Using $ceil — Round Up (quantity / 4)
Example11
1️⃣1️⃣ Using $floor — Round Down (quantity / 4)
Example12
1️⃣2️⃣ Using $trunc — Truncate Value (quantity / 4)
Example13