AggregateCommand.mergeObjects(value: Expression<document>): Object

    聚合操作符。将多个文档合并为单个文档。

    Document 表达式

    Object

    在其它表达式中使用时:

    1. mergeObjects([<document1>, <document2>, ...])

    搭配 group() 使用

    假设集合 sales 存在以下文档:

    1. const $ = db.command.aggregate
    2. db.collection('sales').aggregate()
    3. _id: '$name',
    4. })
    5. .end()

    输出如下:

    一般用法

    假设集合 test 存在以下文档:

    1. { "_id": 1, "foo": { "a": 1 }, "bar": { "b": 2 } }
    2. { "_id": 3, "foo": { "e": 1 }, "bar": { "f": 2 } }

    输出结果如下:

    1. { "_id": 1, "foobar": { "a": 1, "b": 2 } }
    2. { "_id": 3, "foobar": { "e": 1, "f": 2 } }