Nearby lessons
18 of 22🧩 MongoDB: Array and Array Aggregation Operators
MongoDB provides a wide range of Array Operators that help you manipulate, transform, and analyze arrays inside documents.
You can extract elements, merge arrays, filter items, and even perform computations using aggregation pipelines.
📚 Initial Data Setup — studentsArr Collection
Example01
1️⃣ $arrayElemAt — Get Element at Index
Example02
2️⃣ $firstN — First N Elements
Example03
3️⃣ $lastN — Last N Elements
Example04
4️⃣ $maxN — N Largest Values
Example05
5️⃣ $minN — N Smallest Values
Example06
6️⃣ $slice — Extract Subarray
Example07
7️⃣ $sortArray — Sort Elements
Example08
8️⃣ $reverseArray — Reverse Order
Example09
9️⃣ $size — Array Length
Example10
🔟 $in — Check Membership
Example11
1️⃣1️⃣ $indexOfArray — Find Element Index
Example12
1️⃣2️⃣ $isArray — Check If Field Is Array
Example13
1️⃣3️⃣ $map — Transform Each Element
Example14
1️⃣4️⃣ $filter — Filter Elements
Example15
1️⃣5️⃣ $reduce — Compute from Array
Example16
1️⃣6️⃣ $range — Generate Sequence
Example17
1️⃣7️⃣ $concatArrays — Merge Arrays
Example18
1️⃣8️⃣ $zip — Pair Arrays
Example19
1️⃣9️⃣ $arrayToObject — Convert Array → Object
Example20
2️⃣0️⃣ $objectToArray — Convert Object → Array
Example21