I am trying to use the following aggregation:
[
{$unwind: '$names'},
{$sort: {'names.changed_at': -1}},
{$group: {id: '$_id', names: {$push: {value: '$names.value', changed_at: '$names.changed_at'}}}},
{$limit: 3},
{
$lookup: {
from: 'users',
localField: 'id',
foreignField: 'id',
as: 'user',
},
},
{$unwind: '$user'},
{
$project: {
_id: 0,
old_name: {$first: '$names'},
user: {avatar_url: 1, current_tag: 1},
},
}
]
With $lookup and $group it returns []. When I remove either $lookup or $group it works and gives the expected result.
How do I fix this?
