Reputation: 23
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?
Upvotes: 1
Views: 572
Reputation: 1203
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. Any Create, Update or Delete operations have to wait for the lock to be removed, because update operations require an Exclusive (X) lock applied.
References :
MongoDB Locking Types - https://docs.mongodb.com/manual/faq/concurrency/#what-type-of-locking-does-mongodb-use.
MongoDB Tutorial - MongoDB Locks Examples
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.
Upvotes: 2