I have two tables:
productGroups
{number, name}
products (with nested subproduct)
{number, productGroupNumber, subProducts: {barred, showOnHomepage}}
I would like to extract all productGroups which have at least one product that has at least one subproduct that is “!barred && show”.
I started getting unique productGroupNumbers from products, but fails to join them to productGroups.
Any help appreciated
[
{
'$match': {
'subProducts.barred': false,
'subProducts.showOnHomepage': true
}
}, {
'$project': {
'productGroupNumber': '$productGroupNumber'
}
}, {
'$group': {
'_id': null,
'productGroupNumber': {
'$addToSet': '$productGroupNumber'
}
}
}, {
'$unwind': '$productGroupNumber'
}
]