简体   繁体   English

mongodb聚合更新集合

[英]mongodb aggregation on updating collections

How does the aggregation cursor react to CRUD(remove R) operations in the used collections ? 聚合游标如何对使用的集合中的CRUD(remove R)操作作出反应? 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? 该算法是否有可能打印在其操作期间添加或更改的记录?

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. 否。执行聚合操作时,将在集合上应用意图共享(IS)锁,这意味着只能同时发生读取操作。 Any Create, Update or Delete operations have to wait for the lock to be removed, because update operations require an Exclusive (X) lock applied. 任何创建,更新或删除操作都必须等待删除该锁,因为更新操作需要应用互斥(X)锁。

References : 参考文献:

  1. MongoDB Locking Types - https://docs.mongodb.com/manual/faq/concurrency/#what-type-of-locking-does-mongodb-use . MongoDB的锁定类型- https://docs.mongodb.com/manual/faq/concurrency/#what-type-of-locking-does-mongodb-use

  2. MongoDB Tutorial - MongoDB Locks Examples 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. 聚合后对集合的任何更改都不会影响已经计算的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM