Java and MongoDB 4.0 Support for Multi-document ACID Transactions

This article was originally published on MongoDB. Thank you for supporting the partners who make SitePoint possible.


MongoDB 4.0 adds support for multi-document ACID transactions.

But wait… Does that mean MongoDB did not support transactions until now?
No, actually MongoDB has always supported transactions in the form of single document transactions. MongoDB 4.0 extends these transactional guarantees across multiple documents, multiple statements, multiple collections, and multiple databases. What good would a database be without any form of transactional data integrity guarantee?

Before we dive in this blog post, you can find all the code and try multi-document ACID transactions here.

Quick start

Step 1: Start MongoDB

Start a single node MongoDB ReplicaSet in version 4.0.0 minimum on localhost, port 27017.

If you use Docker:

  • You can use
  • When you are done, you can use
  • If you want to connect to MongoDB with the Mongo Shell, you can use

If you prefer to start mongod manually:

  • mkdir /tmp/data && mongod --dbpath /tmp/data --replSet rs
  • mongo --eval 'rs.initiate()'

Step 2: Start Java

The post Java and MongoDB 4.0 Support for Multi-document ACID Transactions appeared first on SitePoint.

Source: Sitepoint