Du kan bruge $map
for at anvende din betingelse for hver shipment
og brug derefter $allElementsTrue
inde i $expr
for at kontrollere, om alle disse elementer matcher:
db.shop_orders.aggregate([
{
$match: { shipments: { $exists: true, $ne: [] } }
},
{
$match: {
$expr: {
$allElementsTrue: {
$map: {
input: "$shipments",
as: "shipment",
in: {
$and: [
{ $eq: [ "$$shipment.status", "Delivered" ] },
{ $lte: [ "$$shipment.deliveredAt", new Date("2018-07-28") ] }
]
}
}
}
}
}
}
])