Now available on Scalingo - MongoDB 4.0

We just released the latest MongoDB databases major version. MongoDB 4.0 is also the new default version when you provision a database. As usual, upgrading is an easy one-click process.

What is new in MongoDB 4.0

MongoDB 4.0 has been released with a few major changes that are worth the discovery. For a comprehensive view on the novelty of this release, you can refer to the release note on the official MongoDB website.

Multi-Document Transactions

MongoDB 4.0 is the first public release including the long-awaited multi-document transactions feature. With this feature, no write operations in a transaction are visible outside it, until a commit is done. It can prove useful when one wants to update multiple documents or ensure consistency of reads to multiple documents.

Here is an example of what a transaction looks like in Python:

with client.start_session() as s:
        collection.insert_one(doc1, session=s)
        collection.insert_one(doc2, session=s)

Note that the performance cost of using multi-document transactions can be high and should be carefully studied.

More information on the official documentation.

A Few Compatibility Changes

As with any new version, MongoDB deprecates a few features, and drops the support of some old deprecated features. You can find a comprehensive list in the official documentation. You may want to go through this document to ensure that your code will still run with MongoDB 4.0.

Upgrade Process

As usual, the upgrading process on Scalingo is as simple as clicking a button on the database dashboard. The following picture shows the message you will see on your database dashboard if you are running the latest 3.6 version (i.e. MongoDB 3.6.3 at the time of writing):

Upgrading to 4.0
Upgrading to 4.0

This upgrade can take some time for the biggest databases. Unless your database uses a Business plan, the upgrade process will induce some downtime. Indeed, all MongoDB databases using a Business plan include a 3 nodes replicaset setup and you will be able to upgrade your database without downtime. Our scheduler (the brain behind all the operations on the platform) is able to achieve this zero-downtime upgrade by following the recommended steps from MongoDB: we first upgrade the secondary members, then step down the primary for an upgraded secondary to take the leadership. Finally, we upgrade the stepped down primary and enable the backwards-incompatible 4.0 features.

Version 4.0.3 has been released. You can find the corresponding Docker images on our Docker hub repository.

You are strongly advised to test that your code still works with the new database version. To ease this task, you can pull the MongoDB version you need from our public Docker hub repository and test it locally, with your code, on your workstation before updating. You can also get the same container that we have built for your app and which is running on our infrastructure using our Docker Image Addon.

Photo by Sandis Helvigs on Unsplash