Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction support in MongoDB

I am new to MongoDB. I read that MongoDB does not support multi-document transactionshere http://docs.mongodb.org/manual/faq/fundamentals/.

If I want to save data in two collections(A and B) atomically, then i can't do that using MongoDB i.e. if save fails in case of B, still A will have the data. Isn't it a big disadvantage?

Still, people are using MongoDB rather than RDBMS. Why?

like image 872
Anand Avatar asked Nov 20 '14 11:11

Anand


3 Answers

MongoDB 4.0 adds support for multi-document ACID transactions now. For reference See Refrence

like image 121
Mithilesh Jha Avatar answered Nov 11 '22 11:11

Mithilesh Jha


UPDATE MongoDB have already started to support multi-document transactions. https://docs.mongodb.com/manual/core/transactions/

MongoDB does not support multi-document transactions.

However, MongoDB does provide atomic operations on a single document. Often these document-level atomic operations are sufficient to solve problems that would require ACID transactions in a relational database.

For example, in MongoDB, you can embed related data in nested arrays or nested documents within a single document and update the entire document in a single atomic operation. Relational databases might represent the same kind of data with multiple tables and rows, which would require transaction support to update the data atomically.

like image 38
Isabel Jinson Avatar answered Nov 11 '22 11:11

Isabel Jinson


MongoDB doesn't support transactions, but saving one document is atomic.

So, it is better to design you database schema in such a way, that all the data needed to be saved atomically will be placed in one document.

like image 3
stalk Avatar answered Nov 11 '22 11:11

stalk