我正在使用桶模式(Bucket Pattern)来划分市场更新的时间序列,以避免超出文档大小限制(传输开销不是问题)。每个文档具有30,000个更新,并且我需要返回匹配“marketId”的所有文档中的这些更新数据组成的数组(最好按顺序排列)。
数据:
{
_id: 60617172eca858909eace71f,
marketId: '1.278363651',
eventId: 5697224,
marketType: 'OVER_UNDER_15',
size: 30000,
updates: [
{
t: 1616998770482.0,
p: 36.49
},
{
t: 1616998770482,
p: 87.77
},
// ... 29998 more
]
},
期望达到的结果:
[
{ t: 1616998770482, p: 36.49 },
{ t: 1616998770482, p: 16.59 },
{ t: 1616998770482, p: 40.38 },
... // sorted by t
}
这是我最接近聚合的尝试:
const result = await db.collection('markets').aggregate(
{ $match: { marketId: marketId } },
{ $project: { _id: 0, updates: 1 } },
{ $unwind: "$updates" },
{ $unwind: "$updates" },
).toArray();
输出:
[
{ updates: { t: 1616998770482, p: 36.49 } },
{ updates: { t: 1616998770482, p: 16.59 } },
{ updates: { t: 1616998770482, p: 40.38 } },
... // actually gives me all of them
}
我该如何删除“更新”并访问实际的对象?