我在mongodb中有这样的集合:
{
product: 1,
basePrice: 100,
seasonalPrices: [{
fromDate: 2017 - 10 - 17 18: 30: 00.000 Z,
toDate: 2017 - 10 - 18 18: 30: 00.000 Z,
delta: 10,
isIncrease: true
}, {
fromDate: 2017 - 10 - 19 18: 30: 00.000 Z,
toDate: 2017 - 10 - 20 18: 30: 00.000 Z,
delta: 10,
isIncrease: false
}]
}, {
product: 2,
basePrice: 200,
seasonalPrices: [{
fromDate: 2017 - 10 - 17 18: 30: 00.000 Z,
toDate: 2017 - 10 - 18 18: 30: 00.000 Z,
delta: 10,
isIncrease: true
}, {
fromDate: 2017 - 10 - 19 18: 30: 00.000 Z,
toDate: 2017 - 10 - 20 18: 30: 00.000 Z,
delta: 10,
isIncrease: false
}]
}

此系列包含产品信息及其基本价格和季节性价格。这里的seasonalPrices字段是包含fromDate,ToDate,delta(增加或减少的百分比)和isIncrease字段的数组,如果为真,则显示季节性价格的增加。
我需要对此集合进行两次查询
"categorizedByPrice": [
// Filter out documents without a price e.g., _id: 7
{ $match: { price: { $exists: 1 } } },
{
$bucket: {
groupBy: "$price",
boundaries: [ 0, 150, 200, 300, 400 ],
default: "Other",
output: {
"count": { $sum: 1 },
"titles": { $push: "$title" }
}
}
}
],

但应该按季节计算价格。
我是mongodb的新手并且难以编写这些mongodb查询。任何帮助表示赞赏。谢谢你的帮助!