MongoDB累计追加

时间:2016-07-09 05:23:58

标签: mongodb aggregation-framework

MongoDB累计追加

我有:

[
    {"d" : 20050511, "u" : 1},
    {"d" : 20050511, "u" : 2},
    {"d" : 20050511, "u" : 3},
    {"d" : 20050511, "u" : 4},

    {"d" : 20050512, "u" : 1},
    {"d" : 20050512, "u" : 2},
    {"d" : 20050512, "u" : 3},
    {"d" : 20050512, "u" : 7},

    {"d" : 20050513, "u" : 18},
    {"d" : 20050513, "u" : 21},
    {"d" : 20050513, "u" : 23}
]

我想将其转换为:

[
    {"d" : 20050511, "u" : 1},
    {"d" : 20050511, "u" : 2},
    {"d" : 20050511, "u" : 3},
    {"d" : 20050511, "u" : 4},

    {"d" : 20050512, "u" : 1},
    {"d" : 20050512, "u" : 2},
    {"d" : 20050512, "u" : 3},
    {"d" : 20050512, "u" : 7}
    {"d" : 20050512, "u" : 4},

    {"d" : 20050513, "u" : 18},
    {"d" : 20050513, "u" : 21},
    {"d" : 20050513, "u" : 23},
    {"d" : 20050513, "u" : 1},
    {"d" : 20050513, "u" : 2},
    {"d" : 20050513, "u" : 3},
    {"d" : 20050513, "u" : 4},
    {"d" : 20050513, "u" : 7}
]

基本上,我希望每个日期累积前进(我将日期存储为整数);意思是20050512它是20050511 + 20050512的独特联盟;对于20050513,它是20050512 + 20050513的独特联盟

我尝试了一些聚合管道衬里,但收效甚微。我可以在应用程序层中执行此操作,但这将导致巨大的i / o和长时间;由于数据超过15年,每个日期有超过50K的文档。

0 个答案:

没有答案