Skip to content
Advertisement

Filtering, mapping and sorting documents in aggregation pipeline

Lets say I have an aggregation pipeline, and I am being able to get the required details as needed but I need to sort values of key named visits in descending order and then cherry pick items in it.

JavaScript

Sample response

JavaScript

Now, what I am looking for is to arrange the visits field in descending order based on _id. And by cherry-picking I mean, selecting only certain items inside visits.

Advertisement

Answer

Hope you have resolved, for the reference this may help you, try lookup with pipeline,

  • let to pass localfield, pipeline to put your conditions in $match stage and your filter conditions you don’t need to filter in $project stage. and put sort by _id in descending order
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement