Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isolation of bulk operations in MongoDB

There's a new kind of operations in 2.6 that's called bulk operations. It resembles me transactions - user can specify a set of writes and subsequently execute them just like described below

var bulk = db.users.initializeOrderedBulkOp();
bulk.insert( { user: "abc123", status: "A", points: 0 } );
bulk.insert( { user: "ijk123", status: "A", points: 0 } );
bulk.insert( { user: "mop123", status: "P", points: 0 } );
bulk.find( { status: "D" } ).remove();
bulk.find( { status: "P" } ).update( { $set: { comment: "Pending" } } );
bulk.execute();

Is bulk operation atomic? Does a potential consumer experiences non-repeatable or phantom reads?

like image 454
madcyree Avatar asked Nov 04 '14 19:11

madcyree


1 Answers

From mongo docs: Operations on a single document are always atomic with MongoDB databases, however, operations that involve multiple documents, which are often referred to as "multi-document transactions", are not atomic.

Ordered vs Unordered Operations

Bulk write operations can be either ordered or unordered. With an ordered list of operations, MongoDB executes the operations serially. If an error occurs during the processing of one of the write operations, MongoDB will return without processing any remaining write operations in the list.

http://docs.mongodb.org/manual/core/bulk-write-operations/

Conclusion: there is no transaction in bulk operations

like image 149
2 revs, 2 users 67% Avatar answered Sep 24 '22 15:09

2 revs, 2 users 67%