AggregateCommand.mergeObjects(value: Expression<document>): Object
聚合操作符。将多个文档合并为单个文档。
Document 表达式
Object
在其它表达式中使用时:
mergeObjects([<document1>, <document2>, ...])
搭配 group() 使用
假设集合 sales
存在以下文档:
const $ = db.command.aggregate
db.collection('sales').aggregate()
_id: '$name',
})
.end()
输出如下:
一般用法
假设集合 test
存在以下文档:
{ "_id": 1, "foo": { "a": 1 }, "bar": { "b": 2 } }
{ "_id": 3, "foo": { "e": 1 }, "bar": { "f": 2 } }
输出结果如下:
{ "_id": 1, "foobar": { "a": 1, "b": 2 } }
{ "_id": 3, "foobar": { "e": 1, "f": 2 } }