Created
August 21, 2023 09:43
-
-
Save icu0755/e5886653c3d1a7e699b69ea298cdb218 to your computer and use it in GitHub Desktop.
Sort and limit mongo collection by parent docs then add corresponding children docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
'$match': { | |
'app': 'nametestsig', | |
'lang': 'en', | |
'label_name': '', | |
'label_value': '', | |
'content_id': { | |
'$ne': '0' | |
} | |
} | |
}, { | |
'$sort': { | |
'kpis.sb_clicks_t': -1 | |
} | |
}, { | |
'$limit': 2 | |
}, { | |
'$lookup': { | |
'from': 'results', | |
'let': { | |
'parentApp': '$app', | |
'parentLang': '$lang', | |
'parentContentId': '$content_id' | |
}, | |
'pipeline': [ | |
{ | |
'$match': { | |
'$expr': { | |
'$and': [ | |
{ | |
'$eq': [ | |
'$app', '$$parentApp' | |
] | |
}, { | |
'$eq': [ | |
'$lang', '$$parentLang' | |
] | |
}, { | |
'$eq': [ | |
'$content_id', '$$parentContentId' | |
] | |
}, { | |
'$ne': [ | |
'$label_name', '' | |
] | |
}, { | |
'$ne': [ | |
'$label_value', '' | |
] | |
} | |
] | |
} | |
} | |
} | |
], | |
'as': 'result' | |
} | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment