Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mogodb Cookbook
// 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