MongoDB中的临时集合 [英] Temporary Collection in MongoDB

查看:337
本文介绍了MongoDB中的临时集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从mongodb MapReduce文档( http://docs .mongodb.org/manual/applications/map-reduce/)-哪些临时集合(优化?)对(业务案例,收益等)有什么好处?

I can't understand this paragraph from mongodb MapReduce documentation (http://docs.mongodb.org/manual/applications/map-reduce/) - what Temporary Collection (optimisation?) is good for (business case, benefits etc)?

临时收藏

map-reduce操作使用临时 在处理过程中收集.完成后,map-reduce操作 重命名临时集合.因此,您可以执行 定期使用相同的目标集合名称进行map-reduce操作 而不会影响中间状态.在以下情况下使用此模式 定期生成统计输出集合.

The map-reduce operation uses a temporary collection during processing. At completion, the map-reduce operation renames the temporary collection. As a result, you can perform a map-reduce operation periodically with the same target collection name without affecting the intermediate states. Use this mode when generating statistical output collections on a regular basis.

推荐答案

让我们说一下{a:1}形式的文档集合,而您定期需要a的平均值.假设您要运行一个map-reduce作业,该作业将每个文档的"a"字段加一.但是,有可能在运行此map reduce时,也获得a平均值的作业正在运行.在这种情况下,如果您没有临时集合,则可能由于map reduce作业尚未完成而使该平均值处于中间状态而使平均值偏离标准.

Lets say you a collection of documents of the form { a : 1 } and periodically you want the average value of a. Lets also say you wanted to run a map-reduce job that incremented the 'a' field by one for every document. It is possible, however, that while this map reduce was running, the job that also gets the average value of a was running. In this case, if you did not have a temporary collection, the average might be thrown off by the fact that the map reduce job did not yet finish, leaving the collection in an intermediate state.

为避免这种情况,map reduce作业可以在临时集合中工作直到完成.完成后,它将临时集合重命名为目标名称,从而有效地交换新集合.这样,当您取平均值"a"时,您得到的值不会受到map-reduce作业的部分影响.

To avoid this situation, the map reduce job can work in a temporary collection until it finishes. Once it is done, it renames the temporary collection to the target name, effectively swapping in the new one. This way, when you take the average value of "a", you get a value that is not partially affected by the map-reduce job.

让我知道您是否希望我对此进行澄清.

Let me know if you would like me to clarify this a bit.

这篇关于MongoDB中的临时集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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