What did MongoDB not being ACID compliant before v4 really mean?
One thing you lose with MongoDB is multi-collection (table) transactions. Atomic modifiers in MongoDB can only work against a single document.
If you need to remove an item from inventory and add it to someone's order at the same time - you can't. Unless those two things - inventory and orders - exist in the same document (which they probably do not).
I encountered this very same issue in an application I am working on and had two possible solutions to choose from:
1) Structure your documents as best you can and use atomic modifiers as best you can and for the remaining bit, use a background process to cleanup records that may be out of sync. For example, I remove items from inventory and add them to a reservedInventory array of the same document using atomic modifiers.
This lets me always know that items are NOT available in the inventory (because they are reserved by a customer). When the customer check's out, I then remove the items from the reservedInventory. Its not a standard transaction and since the customer could abandon the cart, I need some background process to go through and find abandoned carts and move the reserved inventory back into the available inventory pool.
This is obviously less than ideal, but its the only part of a large application where mongodb does not fit the need perfectly. Plus, it works flawlessly thus far. This may not be possible for many scenarios, but because of the document structure I am using, it fits well.
2) Use a transactional database in conjunction with MongoDB. It is common to use MySQL to provide transactions for the things that absolutely need them while letting MongoDB (or any other NoSQL) do what it does best.
If my solution from #1 does not work in the long run, I will investigate further into combining MongoDB with MySQL but for now #1 suits my needs well.
NoSQL database that is with ACID properties and support transaction management
From a recent MongoDB blog post, we can see that MongoDB as of major release 4.0 supports ACID:
MongoDB 4.0 will add support for multi-document transactions, making it the only database to combine the speed, flexibility, and power of the document model with ACID data integrity guarantees. Through snapshot isolation, transactions provide a globally consistent view of data, and enforce all-or-nothing execution to maintain data integrity.
If you happen to be using Spring, all you would have to do to make a method ACID compliant would be to annotate it with @Transactional
. The framework and Mongo would automatically handle the rest.
Related Topics
How to Get the Next Number in a Sequence
Why am I Getting a "[Sql0802] Data Conversion of Data Mapping Error" Exception
Column Does Not Exist in the in Clause, But SQL Runs
Pls-00201: Identifier 'User Input' Must Be Declared
SQL in Query Produces Strange Result
Truncate Timestamp to Arbitrary Intervals
Why Does the Following Join Increase the Query Time Significantly
Using Start Date and End Date in Access Query
Sample Query to Show Cardinality Estimation Error in Postgresql
Column Reference Is Ambiguous in Postgresql Function
How to Build a Summary by Joining to a Single Table with SQL Server
Query JSON Dictionary Data in SQL
What Did Mongodb Not Being Acid Compliant Before V4 Really Mean
How to Check for Is Not Null and Is Not Empty String in SQL Server
How to Drop a Foreign Key Constraint Only If It Exists in SQL Server
How to Identify All Stored Procedures Referring a Particular Table
With (Nolock) VS Set Transaction Isolation Level Read Uncommitted