如何将结果汇总并合并到集合中? [英] How to aggregate and merge the result into a collection?

查看:82
本文介绍了如何将结果汇总并合并到集合中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想聚合结果并将其插入到现有集合中,而不删除该集合.该文档似乎暗示这不是直接可能的.我很难相信.

I want to aggregate and insert the results into an existing collection, without deleting that collection. The documentation seems to suggest that this isn't directly possible. I find that hard to believe.

map-reduce功能具有输出模式",包括合并",它可以实现我想要的功能.我正在寻找聚合的等效项.

The map-reduce functionality has 'output modes', including 'merge', which does what I want. I'm looking for the equivalent for aggregation.

新的 $out 聚合阶段支持插入到集合,但它代替了集合而不是对其进行了更新.如果这样做,我将不得不运行另一个map-reduce将其合并到另一个集合中,这似乎效率很低.

The new $out aggregation stage supports inserting into a collection, but it replaces the collection rather than updating it. If I did this I would (I think) have to run another map-reduce to merge this into another collection, which seems inefficient.

我是否缺少某些功能,或者只是聚合功能中缺少该功能?

Am I missing something or is the functionality just missing from the aggregation feature?

推荐答案

我使用了聚合的输出来插入/合并到集合:

I used the output from aggregation to insert/merge to collection:

    db.coll2.insert(
      db.coll1.aggregate([]).toArray()
    )

这篇关于如何将结果汇总并合并到集合中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆