I am trying to use $push to push a field in an array during aggregation. The push is based on a condition. Here is my code.
Applications.aggregate(
{ $match: { playerUser: userId, playerFeedback: { $exists: false } } },
{ $group: {
_id: '$format',
players: { $push: { $cond: [{ $ne: ['$status', 'invite']}, "$player", null] }},
invite: { $sum: { $cond: [{ $eq: ['$status', 'invite']}, 1, 0] } }
} },
{
$lookup: {from: 'players', localField: 'players', foreignField: '_id', as: 'players'}
},
{
$project : {
"players.name" : 1,
"players.Url" : 1,
"invite" : 1,
"applied": 1
}
}
This seems to work on my staging environment, which has mongodb v3.4. But it doesn't work on my production env, mongodb v3.2; although I am not sure if version is an issue here. Can someone help?