mongodb在更新集合上的聚合 [英] mongodb aggregation on updating collections

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

问题描述

聚合游标如何对使用的集合中的CRUD(remove R)操作作出反应? 例如:

How does the aggregation cursor react to CRUD(remove R) operations in the used collections ? For example:

db.collection('aggregate')
.aggregate([
      {$match: {}},
      {$project:
        { newField: {$literal: "new value"} }
      }
]).each(function(err, doc) {      
  // do editin inserting and removing on 'aggregate' collection    
 print(doc)
});

该算法是否有可能打印在其操作期间添加或更改的记录?

Is there a chance that the algorithm will print records added or changed during its operation?

推荐答案

该算法是否有可能打印添加的记录或 在操作过程中发生了变化?

Is there a chance that the algorithm will print records added or changed during its operation?

不.执行聚合操作时,将在集合上应用意图共享(IS)锁,这意味着只能同时发生读取操作.所有的创建,更新或删除操作都必须等待删除该锁,因为更新操作需要应用互斥(X)锁.

No. When an Aggregate Operation is performed, there would be an Intent Shared (IS) lock applied on the collection, which means only read operations could happen concurrently. Any Create, Update or Delete operations have to wait for the lock to be removed, because update operations require an Exclusive (X) lock applied.

参考文献:

  1. MongoDB锁定类型- MongoDB教程-聚合操作处理数据记录并返回计算结果.将游标应用于计算结果.聚合后对集合的任何更改都不会影响已经计算的结果.

    Aggregation operations process data records and return computed results. Cursor is applied on the computed results. Any changes to the collection after aggregation does not affect the already computed results.

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

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