Answer the question
In order to leave comments, you need to log in
How to do two-level aggregation in a query?
Good afternoon!
There are currently 3 collections, with this format:
let item = {
_id: "...",
}
let itemGroup = {
_id: "..."
}
let relation = {
item_id: "...",
group_id: "..."
}
group.aggregate([
{
$project: {
_id: {
$toString: '$_id',
},
title: 1,
order: 1,
},
},
{
$lookup: {
from: 'fields',
localField: '_id',
foreignField: 'group_id',
as: 'fields',
},
},
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question