0
我有一個集合,如:
{
_id: 0,
items: [
{ item_id: 43, quantity: 2, price: 10 },
{ item_id: 2, quantity: 1, price: 240 }
],
T: [
{ item_id: 2993, quantity: 3, price: 110 },
{ item_id: 90103, quantity: 4, price: 5 },
{ item_id: 398, quantity: 1, price: 300 }
]
}
{
_id: 1,
items: [
{ item_id: 23, quantity: 3, price: 110 },
{ item_id: 103, quantity: 4, price: 5 },
{ item_id: 38, quantity: 1, price: 300 }
],
T: [
{ item_id: 23, quantity: 3, price: 110 },
{ item_id: 103, quantity: 4, price: 5 },
{ item_id: 38, quantity: 1, price: 300 }
]
}
{
_id: 2,
items: [
{ item_id: 4, quantity: 1, price: 23 }
],
T: [
{ item_id: 203, quantity: 3, price: 110 },
{ item_id: 003, quantity: 4, price: 5 },
{ item_id: 398, quantity: 1, price: 300 }
]
}
我想回到一個價格> = 100這與以下完成的項目陣列中的所有項目:
$project: {
items: {
$filter: {
input: "$items",
as: "item",
cond: { $gte: [ "$$item.price", 100 ] }
}
}
}
我怎樣才能在items
陣列和T
陣列具有價格> = 100的所有元素上展開該表達式到$filter
?
JohnnyHK你好,我想給T和物品陣列都具有相同的基本過濾條件。所以我期望輸出是T和items數組只包含價格大於等於100的元素的所有文檔 –