Created
July 2, 2020 08:26
-
-
Save technoknol/1fd09a97b3c0f65fb6921b5e4107ff45 to your computer and use it in GitHub Desktop.
Mogodb Cookbook
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
// to prevent empty objects being pushed in resule like 'eventWinners' : [ {} ] | |
// if there are no winners found, after lookup and unwind. | |
$group: { | |
_id: '$_id', | |
root: { | |
$mergeObjects: '$$ROOT', | |
}, | |
eventWinners: { | |
$push: { | |
$cond: { | |
if: { $eq: ["$eventWinners", {}] }, | |
then: '$$REMOVE', | |
else: '$eventWinners', | |
} | |
} | |
}, | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment