Hey all,
A noob here trying to understand a somewhat complex aggregate thing. I can I $project certain fields in a after a nested $lookup. See the { $project: { “uid.email”: 1 } },
this.aggregate([
{
$facet: {
meta: [{ $match: query }, { $count: "totalHits" }],
items: [
{ $match: query },
{
$addFields: {
id: { $toString: "$_id" },
},
},
{ $sort: sorting },
{ $skip: perPage * (page - 1) },
{ $limit: perPage },
{
$lookup: {
from: 'users',
localField: 'uid',
foreignField: '_id',
as: 'uid',
},
},
{ "$unwind": "$uid" },
{
$lookup: {
from: 'items',
localField: 'items.item',
foreignField: '_id',
as: 'items',
},
},
// Here is where I would like to $project only certain fields in the array from the $lookup above
],
matchingTags: [
{ $match: query },
{ $project: { tags: 1 } },
{ $unwind: "$tags" },
{ $group: { _id: "$tags", count: { $sum: 1 } } },
{ $sort: { count: -1 } },
],
},
},
])
Any hints?