MongoDB’s latest major release, v5.0, was launched on July 13th, 2021. This iteration of the document-oriented database adds new features and improvements as well as a revised release cadence for future versions.
Time Series Data
One of the headline feature additions is first-class support for time series data. While some developers have already built their own time series tooling around MongoDB, having time series data types natively available will help many more to get started.
A “time series” refers to any kind of data where records are created sequentially at different points in time. Common use cases include sensor measurement streams and transaction history logs, where each record corresponds directly to a particular moment.
New time series collections provide a special data store that’s optimized for data with these characteristics. Values will be compacted into a unique schema structure when persisted to disk, providing better indexing, more efficient storage use, and reduced server load. You can set the granularity of time data to seconds, minutes, or hours. It’s also possible to automatically expire data after a set number of seconds.
The snippet above defines a time series collection called measurements. Its granularity is set to minutes. Documents in the collection will be automatically deleted after an hour.
MongoDB 5.0 provides built-in support for querying and manipulating time series data too. You can extract time-based moving averages that track temporal trends with minimal code of your own.
Assuming a time series collection with timestamp and measurement fields, the above aggregate command would output something like this:
The records are grouped by their timestamp using a projection. Each group’s measurement values are then averaged into the averageMeasurement field.
Live Resharding
One of the biggest challenges with horizontally scaling MongoDB has been its approach to sharding. Choosing the correct shard key is critical to your cluster’s performance but was previously a one-way operation. Once you’d set the key, you couldn’t change it, leaving you powerless if you made the wrong decision on day one. MongoDB itself described shard key selection as a “one-way parachute jump” best resolved by creating a whole new cluster.
MongoDB 5.0 finally puts an end to shard key nightmares. If you get it wrong, you can re-index your collections using a new shard key. MongoDB will handle the entire migration for you, without causing any database downtime. This makes it much easier to escape subpar performance caused by incorrect shard configuration.
Versioning and Releases
MongoDB 5.0 brings significant future-proofing enhancements. The database has gained a versioned API which lets you avoid breaking changes as you upgrade to new releases.
You’ll be able to update to future versions without modifying your app’s code. Everything will work seamlessly as long as the new release supports the API version you target. It means your application is more decoupled from the underlying database version, so you can upgrade to new MongoDB versions earlier without risking broken code.
Accompanying this change is a new release schedule. MongoDB will start shipping future versions more quickly, with a “Rapid Release” coming out every quarter. These will be minor semantic versions with no breaking changes, providing new features in an accelerated cycle. Each year, a new major release will arrive, rolling up the Rapid Releases and potentially breaking backwards compatibility.
The new release model lets you access emerging features more quickly without impacting MongoDB’s overall stability. If you don’t want to upgrade each quarter, you can stay on the major release branch and retain the annual cadence. Rapid releases will only be officially supported in MongoDB’s managed Atlas service. They’ll be available for self-hosted users as optional development builds.
Serverless MongoDB
MongoDB has also launched a preview of its new serverless Atlas instances. Atlas is the company’s official database-as-a-service offering for popular cloud platforms.
With serverless deployment, you’ll get automatic provisioning of the correct resources for your current workload. The platform automatically adapts to changing demands, so you don’t need to manually scale your infrastructure. You’ll only be billed for what you use.
Serverless Atlas is managed by MongoDB. It uses the latest database release version with support for automatic upgrades. Creating serverless instances lets you access new MongoDB clusters without configuring them yourself. You pick a cloud provider, create a new database, and connect from your application.
Summary
MongoDB 5.0 extends the database with more capabilities that enhance its versatility. It also cements its position as a cloud-native platform that’s available in a range of managed solutions, now including serverless options.
Besides the headline changes, there’s a healthy selection of ecosystem improvements and enhancements. A new MongoDB Shell simplifies developer interaction with databases by offering syntax highlighting and autocomplete. New SDKs also help integrate MongoDB with more programming languages and frameworks, including Unity, Flutter and Kotlin.
On the security front, expanded support for Client-Side Field Level Encryption lets you encrypt data residing in multi-cloud databases. Certificate rotation improvements facilitate x509 swaps without downtime, reducing the impact of routine hardening procedures.