Articles → MONGODB → $Sort Operator In MongoDB
$Sort Operator In MongoDB
Purpose
Syntax
db.[collection].aggregate([
{ $sort: { field1: 1 } }
])
- 1 indicates sorting in ascending order.
- -1 indicates sorting in descending order.
Example
db.mycollection.aggregate([
{ $sort: { age: -1 } }
])
Output
Posted By - | Karan Gupta |
|
Posted On - | Monday, April 1, 2024 |