Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between sort with aggregation and sort with find

Tags:

mongodb

Is there any difference between following two queries, please explain

db.grades.aggregate([{$sort: {type:1 score:1 } }])

and

db.grades.find().sort({type:1, score:1})

I got the same result when I run these queries, please explain functional and performance differences

Thanks

like image 770
AshokGK Avatar asked Jan 25 '26 05:01

AshokGK


1 Answers

sort() applies to the documents that are being returned.

$sort applies to all of the element inside of such documents.

like image 163
RRPatel Avatar answered Jan 28 '26 23:01

RRPatel