I am learning about mongodb. If I create a bulk write is this transaction all or nothing? I have a scenario where my users can delete who they are following. For this to happen I need to delete from user A who they are following and from User B the follower. For consistency I need these to occur as a all or nothing because I wouldn't want only 1 of the 2 operations to succeed as this would cause bad data. Reading the docs:


I could not find the answer.


MongoDB transactions are always atomic on single document. However, if it involves multiple documents transactions are not atomic.

Coming to Bulk operations, there is no transactions concept. For example, you are inserting 100 documents in a collection, if 51st insert fails, MongoDB will not insert the remaining documents in the list as it executes the bulk operations serially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.