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
Loading editor…

1️⃣ Using $add — Add Values

Example02
Loading editor…

2️⃣ Using $subtract — Subtract Values

Example03
Loading editor…

3️⃣ Using $multiply — Multiply Values

Example04
Loading editor…

4️⃣ Using $divide — Divide Values

Example05
Loading editor…

5️⃣ Using $mod — Modulus (Remainder)

Example06
Loading editor…

6️⃣ Using $pow — Exponentiation (price²)

Example07
Loading editor…

7️⃣ Using $round — Round Result (price / 3)

Example08
Loading editor…

8️⃣ Using $sqrt — Square Root (√price)

Example09
Loading editor…

9️⃣ Using $abs — Absolute Value (|price - 200|)

Example10
Loading editor…

🔟 Using $ceil — Round Up (quantity / 4)

Example11
Loading editor…

1️⃣1️⃣ Using $floor — Round Down (quantity / 4)

Example12
Loading editor…

1️⃣2️⃣ Using $trunc — Truncate Value (quantity / 4)

Example13
Loading editor…

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.