MongoDB 3.4 is now available on Compose


We are pleased to announce that MongoDB 3.4.10 is now available to new and existing Compose users.

You can now select MongoDB 3.4.10 when creating your new MongoDB deployment on Compose and get all the Compose features - automated backups, auto-scaling and more - with your database deployment. Just sign up for a account and go. Existing MongoDB users who want to upgrade should skip to Upgrading to 3.4. Or read on, and learn what MongoDB 3.4 can do for you.

MongoDB 3.4 brings with it an enhanced aggregation pipeline with graph operations and faceted navigation to allow multiple pipelines to be processed. There's also read-only views, support for decimal128 format numbers and collation support for many operations. It's a release which has many useful user-facing features so let's have a quick look them:


Read-only views are new in MongoDB 3.4 and they let developers create what appear to be unwritable collections based on other collections. Limiting who could read a collection in MongoDB has been historically hard, but with read-only views, a developer can now extract the relevant parts of a collection to other applications. They can be safe in the knowledge that attempts to write to this new view will fail, and they can restrict access to the collection it is sourced from.

The catch is that read-only views on MongoDB are non-materialized views. They don't use any disk space because they are created on-the-fly when the view is accessed. When they are accessed, the aggregation pipeline specified with the view runs on the collection. Typically, this might be a $project stage to extract the required fields from the source collection. The pipeline needs to be quick to run, so make sure it isn't triggering full scans and indexes exist on the source collections to keep your performance up. Read more in the views section of the MongoDB documentation.

Aggregation and $graphLookup

The $graphLookup stage is added in 3.4 to allow a pipeline to recursively lookup values in another collection. You can set which collection is queried, which field provides the starting point for the descent, what field to match with and how you want the results added to your record. There are also options to restrict depth of search and record that search depth. There's some accessible examples in the official documentation.

This makes it possible to represent various graph networks and hierarchies in MongoDB and make use of that data while processing inside the database, rather than pulling it into your application for processing.

Buckets and Facets in aggregation

When you want to split up documents into groups based on a field, aggregation has you covered in MongoDB 3.4. Using the $bucket stage, you can group documents into bound sets and work with those sets. Want to group documents in multiple different ways? Use $facet with $bucket to perform the multiple splits and sorts in one step. Not sure what the boundaries should be for your buckets? Let $bucketAuto take the strain and tell it how many buckets you want; it'll work out the boundaries for you.

Together, they make it much easier to slice and dice reports using MongoDB's aggregation.

Aggregate Enhancements

As you might be able to tell, 3.4 has had a lot of work done on aggregation. There are now stages which can add fields to a document or extract documents from within other documents making it easier to reshape the data passing through the pipeline. Arrays in aggregation are now easier to work with index, in, range, reverse, reduce and zip operators allowing arrays to be inspected, data extracted, processed or joined with other arrays.

Strings have had their own set of enhancements with support for UTF8-aware measuring, searching and extracting of strings and easy splitting of strings into arrays. There's also a new $switch to make repetitive flow control simpler to write.

Decimal Types

Numbers can be tricky to work with binary rounding errors creeping in. The NumberDecimal type introduced in MongoDB 3.4 addresses that by adding decimal128 support - 128 bits of numeric representation giving 34 decimal digits and an exponent range of -6143 to 6144. You'll need to update your MongoDB drivers to use it and, most likely add Decimal128 support to your application. But if you need a precise numeric representation in your application which isn't going to go awry, NumberDecimal is the way to go.

Upgrading to 3.4

Upgrading on Compose to 3.4 depends on your current version of MongoDB. If you have a MongoDB deployment version 3.2.11 or later, you will be able to go to Settings in your database's Compose console, go to the Change Version panel, select 3.4.10 in the options and click on Change Version to being your update.

If you have a MongoDB 3.2.10 (or earlier) system, things are a little more complex. For various reasons, MongoDB 3.2.10 on Compose has a number of issues that make doing an in-place upgrade difficult to do reliably. With that in mind, we're not directly offering a MongoDB 3.2.10 upgrade. You can upgrade to MongoDB 3.4 using our Restore from Backup functionality. As this creates a new deployment, the new deployment automatically has the new configuration server system set up and data is then restored to it.

There are two additional caveats to this process. Be prepared to recreate your user/roles data in the new server, if you use that functionality. The backups for 3.2.10 do not contain a restorable version of that information for later versions of the database. Also, if you modified your connection strings to use Let's Encrypt certificates - available on some 3.2.10 deployments - migrating to 3.4 returns MongoDB to only having self-signed certificates available. You will have to download those certificates and set up your connections to use them. That's covered in the documentation.

To make use of this upgrade, make sure you have a complete and current backup and follow the instructions in the documentation for restoring from a backup. Select 3.4.10 as the version of the new deployment and the process should be automatic from there. Remember that Compose's support team is ready and waiting if you have any issues with migrating.

Read more articles about Compose databases - use our Curated Collections Guide for articles on each database type. If you have any feedback about this or any other Compose article, drop the Compose Articles team a line at We're happy to hear from you.

attribution Sweet Ice Cream Photography

Dj Walker-Morgan
Dj Walker-Morgan was Compose's resident Content Curator, and has been both a developer and writer since Apples came in II flavors and Commodores had Pets. Love this article? Head over to Dj Walker-Morgan’s author page to keep reading.

Conquer the Data Layer

Spend your time developing apps, not managing databases.