Should Mongo be considered if ACID/transaction is required ?

110 views
Skip to first unread message

emilly

unread,
May 29, 2016, 8:05:27 AM5/29/16
to mongodb-user
I am beginner in MongoDB but read a lot of stuff on net in last week. What I get is MongoDB does not follow the ACID/transaction principles across documents/collections (like relational datatbase) which is need of most of web application if not all
(For example scenarios like transfer amount from one account to another). Here is my take on each principle

Atomicity :- In most of the enterprise/web application we need scenarios like where a transaction contains multiple DML statements. As MongoDB
does not support it. One way is either i go for manually two phase commit or some other approach. But i believe its better to consider
relational DB when traction is required instead of MongoDB as relational DB are designed for the same

Consitency :- I don't care much as i can achieve it at app layer also without much effort

Isolation :- As Mongo odel is similar to  auto commits transaction for relational databases. It means each upadte is visible to another transaction
as soon as it is fired instead of doing at commit time

Durable:- In Mongo DB, if commit is fired and unfortunately system crash, Mongo by default can not recover the last transaction. If i need to recover it
for some reason,should i consider Mongo or i should stick to relational DB?


As per mine understanding Mongo DB makes sense where we don't have transaction requirement and we need to do data analysis on humongous data?

Rhys Campbell

unread,
May 30, 2016, 2:32:26 AM5/30/16
to mongodb-user

Does MongoDB support ACID transactions?



"Yes, but in a limited sense. MongoDB supports ACID transactions at the document level; today MongoDB does not support multi-document transactions. For many but not all applications, this is sufficient because data for a record tends to be managed as a single document. Like most databases, MongoDB uses write-ahead logging to an on-disk journal to guarantee write operation durability and to provide crash resiliency."

Asya Kamsky

unread,
May 30, 2016, 11:42:58 PM5/30/16
to mongodb-user
Just want to point out a possible misconception in your question:

You imply that transaction is necessary in "scenarios like transfer
amount from one account to another" but that's not how banks work, or
worked for the last many decades.

If you want to transfer $200 from your checking account to my savings
account, do you think that a two phase commit transaction in the DB
can be used to implement this? It cannot - for one thing, we bank at
two different banks. The "transfer $" is probably the most commonly
used example as why transactions are necessary and it's probably the
least applicable one as that's not at all how the banks achieve
consistency in their financial transactions. [1]

Asya
[1] if it was, then how would they have gotten it done before RDBMS
existed and supported two phase commit transactions?
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> https://docs.mongodb.org/manual/support/
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/b8b54546-e79e-449d-bb2b-302725a5e03e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

emilly

unread,
May 31, 2016, 1:42:55 AM5/31/16
to mongodb-user
@Asya

Consider the simple scenario where i need to transfer the amount from one account to another account with in same bank.

This is just one example. Another example can be where employee entity can not be created with out address. Now if there is some error while inserting/updating
the address record i need to rollback complete transaction instead of stale data under employee collection  or i need to store complete document in one
collection

@Rhys Campbell
You said "For many but not all applications, this is sufficient because data for a record tends to be managed as a single document..."
I come from RDBMS background. In last 10 years of experience i see in almost every enterprise application we need atomicity across documents/table
or either collection should be very generic to contain all related data in itself instead of segregating it across the collection

Asya Kamsky

unread,
May 31, 2016, 2:49:18 AM5/31/16
to mongodb-user
I've spent more years working with RDMBS before I came to MongoDB than 10. :)

Let's just say there are many more ways to skin a cat, so to speak.
> https://groups.google.com/d/msgid/mongodb-user/91cdeca2-16f0-41cc-b070-d3aa0ca0cd47%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages