将mongodb聚合框架结果导出到新集合 [英] Export mongodb aggregation framework result to a new collection

查看:51
本文介绍了将mongodb聚合框架结果导出到新集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将聚合框架结果保存到新集合中. 我知道目前使用命令本身使用框架是不可能的.

I want to save the aggregation framework result to a new collection. I know that's impossible with the framework at the moment with the command itself.

外壳中是否有解决方法?

Is there a workaround in the shell?

推荐答案

更新:请参阅萨尔瓦多的 answer ,以便在MongoDB 2.6+中更有效地做到这一点.

Update: See Salvador's answer for a more efficient way to do this in MongoDB 2.6+.

将聚合结果保存到变量中,然后将其result属性插入新集合中:

Save the aggregation result in a variable and then insert its result property into a new collection:

var result = db.foo.aggregate(...);
db.bar.insert(result.result);

这篇关于将mongodb聚合框架结果导出到新集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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