Isolation of bulk operations in MongoDB
Asked Answered
B

1

7

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?

Banas answered 4/11, 2014 at 19:22 Comment(0)
O
12

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

Orella answered 4/11, 2014 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.