MongoDB展开元数据库的前20组时间序列

时间:2019-06-08 16:51:15

标签: mongodb mongodb-query metabase

输入:我有数百个事件源,这些事件源生成事件,每个事件存储在MongoDB中的方式为:

{
   eventSourceName: "LondonDC"
   score: 0.4
   timestamp: 16745735746
},
{
   eventSourceName: "LondonDC"
   score: 0.5
   timestamp: 16745745746
},
{
   eventSourceName: "DublinDC"
   score: 0.8
   timestamp: 16745765746
}

score字段会不时变化,并且我想绘制按得分排序的前20个事件源的score字段的时间序列折线图(因此,我将看到前20名表演者)

我尝试使用unwind,但没有帮助:

[ 
    { "$unwind": "$data" }, 
    {
        "$lookup": {
            "from": "data",
            "localField": "data",
            "foreignField": "_id",
            "as": "resultingArray"
        }
    }, 
    { "$unwind": "$resultingArray" },
    {       
        "$group": {
            "_id": "$name",
            "data": { "$push": "$resultingArray" }
        }

    }
]

0 个答案:

没有答案