У меня есть две коллекции Upload
и Notification
, и я хочу populate
imageid
из Notification
с _id
из Upload
Collection. Однако $lookup
возвращает пустой массив
const user = req.user.id;
const aggregation = await Notification.aggregate(
[
{
$group: {
_id: { imageid: '$imageid' },
to_userid: { $first: user },
opened: { $first: '$opened' },
imageid: { $first: '$imageid' },
notification_date: { $first: '$notification_date' },
total: { $sum: 1 }
}
},
{
$lookup: {
from: "Upload",
localField: "imageid",
foreignField: "_id",
as: "images"
}
},
]
)