MongoDB汇总来自两个集合的返回数据

时间:2019-10-01 18:40:45

标签: mongodb

我想返回2个集合的结果,每个结果都包含这2个集合之一。这两个集合必须按创建日期排序,例如,以10为限制。

例如:

CollectionA:

[
    { title: "Collection A - 1", createdAt: new ISODate('2019-08-25T00:00:00.000Z') },
    { title: "Collection A - 2", createdAt: new ISODate('2019-09-15T00:00:00.000Z') },
]

CollectionB:

[
    { title: "Collection B - 1", createdAt: new ISODate('2019-08-26T00:00:00.000Z') },
    { title: "Collection B - 2", createdAt: new ISODate('2019-09-20T00:00:00.000Z') },
]

我想要的结果:

[
     { title: "Collection B - 2", createdAt: new ISODate('2019-09-20T00:00:00.000Z') },
     { title: "Collection A - 2", createdAt: new ISODate('2019-09-15T00:00:00.000Z') },
     { title: "Collection B - 1", createdAt: new ISODate('2019-08-26T00:00:00.000Z') },
     { title: "Collection A - 1", createdAt: new ISODate('2019-08-25T00:00:00.000Z') },
]

0 个答案:

没有答案
相关问题