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

查看:13
本文介绍了将 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.

shell 中有解决方法吗?

Is there a workaround in the shell?

推荐答案

更新:参见 Salvador 的 答案 用于在 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天全站免登陆