MongoDB Aggregation Framework - $sort stage

๐Ÿ’ง $sort stage:

With the $sort stage we can sort input documents or output documents from stage to ascending or descending order.

๐Ÿ‘‰ Syntax: 

db.collection.aggregate([{$sort: {<field> = < -1 | 1 >, <field2>: < -1 | 1 >...}} ])

Here, -1 represents the descending order and 1 represents the ascending order.

Stage order:

$match --> $group --> $sort --> $count


Post a Comment

Previous Post Next Post