Navigation

Release Notes for MongoDB 5.0

On this page

Note

MongoDB 5.0 Released Jul 13, 2021

Issues fixed:

MongoDB 5.0 introduces time series collections which efficiently store sequences of measurements over a period of time. Compared to normal collections, storing time series data in time series collections improves query efficiency and reduces disk usage for your data and indexes.

MongoDB 5.0 introduces the following aggregation operators:

Operator
Description

$count (aggregation accumulator) provides a count of all documents when used in the existing pipeline $group (aggregation) stage and the new MongoDB 5.0 $setWindowFields stage.

Note
Disambiguation
Increments a Date object by a specified number of time units.
Returns the difference between two dates.
Decrements a Date object by a specified number of time units.
Returns the value of a specified field from a document. You can use $getField to retrieve the value of fields with names that contain periods (.) or start with dollar signs ($).
Adds the $sampleRate method to probabilistically select documents from a pipeline at a given rate.
Adds, updates, or removes a specified field in a document. You can use $setField to add, update, or remove fields with names that contain periods (.) or start with dollar signs ($).
The $rand method generates a random float value between 0 and 1 each time it is called. The new $sampleRate operator is based on $rand. (Also added to MongoDB 4.4.2)

MongoDB 5.0 introduces the $setWindowFields pipeline stage, allowing you to perform operations on a specified span of documents in a collection, known as a window. The operation returns the results based on the chosen window operator.

For example, you can use the $setWindowFields stage to output the:

  • Difference in sales between two documents in a collection.
  • Sales rankings.
  • Cumulative sales totals.
  • Analysis of complex time series information without exporting the data to an external database.

Starting in MongoDB 5.0, the $eq, $lt, $lte, $gt, and $gte operators placed in an $expr operator can use indexes to improve performance.

Starting in MongoDB 5.0, you can specify multiple input expressions for the $ifNull expression before returning a replacement expression.

Starting in MongoDB 5.0, the aggregate command and db.collection.aggregate() helper method have a let option to specify a list of variables that can be used elsewhere in the aggregation pipeline. This allows you to improve command readability by separating the variables from the query text.

Starting in MongoDB 5.0, an aggregation pipeline $lookup stage supports concise correlated subqueries that improve joins between collections.

Starting in MongoDB 5.0, Change Events contain the field updateDescription.truncatedArrays to record array truncations.

MongoDB 5.0 removes the deprecated geoHaystack index and geoSearch command. Use a 2d index with $geoNear or one of the supported geospatial query operators instead.

Upgrading your MongoDB instance to 5.0 and setting featureCompatibilityVersion to 5.0 will delete any pre-existing geoHaystack indexes.

The db.collection.createIndex() and db.collection.createIndexes() operations have new error messages when options are specified incorrectly.

If a node in a replica set is cleanly shutdown or rolls back during an index build, the index build progress is now saved to disk. When the server restarts, index creation resumes from the saved position.

Starting in MongoDB 5.0, the reIndex command and the db.collection.reIndex() shell method may only be run on standalone instances.

Starting in MongoDB 5.0, these database commands and mongo shell helper methods are removed:

Removed Command
Alternative
Not available
Not available
Not available

Starting in MongoDB 5.0 (and 4.4.2, 4.2.10, 4.0.21, and 3.6.21), the hello command and the db.hello() method were introduced as replacements for the isMaster command and the db.isMaster() method. The new topology metric connections.exhaustHello tracks this in connections.

Starting in MongoDB 5.0, mongod and mongos enter a quiesce period to allow any ongoing database operations to complete before shutting down.

Starting in MongoDB 5.0, the members[n]._id field may be any integer value greater than or equal to 0. Previously, this value was limited to an integer between 0 and 255 inclusive.

Starting in MongoDB 5.0, enableMajorityReadConcern and --enableMajorityReadConcern cannot be changed and are always set to true due to storage engine improvements.

In earlier versions of MongoDB, enableMajorityReadConcern and --enableMajorityReadConcern are configurable and can be set to false to prevent storage cache pressure from immobilizing a deployment with a three-member primary-secondary-arbiter (PSA) architecture.

If you are using a three-member primary-secondary-arbiter (PSA) architecture, the write concern "majority" can cause performance issues if a secondary is unavailable or lagging. See Mitigate Performance Issues with PSA Replica Set for advice on how to mitigate these issues.

Starting in MongoDB 5.0, you can use the new replWriterMinThreadCount server parameter to configure the timeout of idle threads in the thread pool for parallel execution of replication operations. When replWriterMinThreadCount is configured with a value less than replWriterThreadCount, idle threads above replWriterMinThreadCount are timed out.

When reconfiguring primary-secondary-arbiter (PSA) replica sets or changing to a PSA architecture, it is now in some cases required to perform the reconfiguration in a two-step change. MongoDB 5.0 introduces the rs.reconfigForPSASet() method which performs both steps. If you cannot use the helper method, follow the procedure in Modify PSA Replica Set Safely.

Starting in MongoDB 5.0, you may now rotate the following TLS certificates on demand without first needing to stop your running mongod or mongos instance:

To rotate these certificates, replace the certificate files on your filesystem with updated versions, then use the rotateCertificates command or the db.rotateCertificates() shell method to trigger certificate rotation.

Rotating certificates in this manner does not require downtime, and does not drop any active remote connections.

See Online Certificate Rotation for full details.

MongoDB 5.0 introduces the opensslCipherSuiteConfig parameter to enable configuration of the supported cipher suites OpenSSL should permit when using TLS 1.3 encryption.

The ideal shard key allows MongoDB to distribute documents evenly throughout the cluster while facilitating common query patterns. A suboptimal shard key can lead to performance or scaling issues due to uneven data distribution. Starting in MongoDB 5.0, you can use the reshardCollection command to change the shard key for a collection to change the distribution of your data across your cluster.

Starting in MongoDB 5.0, the $currentOp aggregation stage (and the currentOp command and db.currentOp() shell method) include additional information about the status of ongoing resharding operations for the resharding coordinator and the donor and recipient shards.

Starting in MongoDB 5.0 (also available starting in 4.4.5 and 4.2.13), MongoDB adds the parameter option "automatic" as the new default for the ShardingTaskExecutorPoolReplicaSetMatching. When set for a mongos, the instance follows the behavior specified for the "matchPrimaryNode" option. When set for a mongod, the instance follows the behavior specified for the "disabled" option.

Starting in MongoDB 5.0, you can use the renameCollection command to change the name of a sharded collection.

The mongo shell has been deprecated in MongoDB v5.0. The replacement shell is mongosh. The legacy mongo shell will be removed in a future release.

Shell packaging also changes in MongoDB v5.0. Refer to the installation instructions for further details.

Starting in MongoDB 5.0 (and MongoDB 4.4.5), the Google Cloud Platform KMS and Azure Key Vault are supported in both mongosh and the legacy mongo shell as Key Management Service (KMS) providers for Client-Side Field Level Encryption.

Using a KMS, you can centrally and securely store Customer Master Keys (CMKs), which are used to encrypt and decrypt data encryption keys as part of the client-side field level encryption workflow.

In addition, a configured KMS allows for the use of Automatic Field Decryption of data fields when used with MongoDB Enterprise.

Instructions are available for both shells:

Starting in MongoDB 5.0, read concern "snapshot" is supported for some read operations outside of multi-document transactions on primaries and secondaries.

Starting in MongoDB 5.0, you can use the minSnapshotHistoryWindowInSeconds parameter to control how long WiredTiger keeps the snapshot history.

Starting in MongoDB 5.0, the new server parameter coordinateCommitReturnImmediatelyAfterPersistingDecision controls when transaction commit decisions are returned to the client. In previous versions of MongoDB, the shard transaction coordinator waited for all members to acknowledge a multi-document transaction commit before returning the commit decision to the client.

Starting in MongoDB 5.0, the implicit default write concern is w: majority. However, special considerations are made for deployments containing arbiters:

  • If the number of data-bearing voting members is not strictly more than the voting majority, the default write concern is w: 1.
  • In all other scenarios, the default write concern is w: "majority".

Specifically, MongoDB uses the following formula to determine the default write concern:

if [(#arbiters > 0) AND (#arbiters >= ½(#voting nodes) - 1)]
defaultWriteConcern = { w: 1 }
else
defaultWriteConcern = { w: majority }

Starting in MongoDB 5.0, startup and logout audit action types are available in System Event Audit Messages.

The dropCollection audit action type (atype) adds an audit event when a view is dropped.

Starting in MongoDB 5.0, the new parameter mongosShutdownTimeoutMillisForSignaledShutdown specifies the time in milliseconds to wait for any ongoing database operations to complete before initiating a shutdown of mongos.

MongoDB 5.0 introduces the zstdCompressionLevel configuration file option which allows for configurable compression levels when blockCompressor is set to zstd.

Starting in MongoDB 5.0, the following read operations are not blocked when another operation holds an exclusive (X) write lock on the collection:

When writing to a collection, mapReduce and aggregate hold an intent exclusive (IX) lock. Therefore, if an exclusive X lock is already held on a collection, mapReduce and aggregate write operations are blocked.

MongoDB 5.0 adds detailed explanations when a document fails schema validation.

Starting in MongoDB 5.0, the validate command and db.collection.validate() helper method have a new repair option for repairing a collection that has inconsistencies.

The validate command and db.collection.validate() helper method also return a new repaired boolean value that is true if the collection was repaired.

Starting in MongoDB 5.0, the --repair option for mongod validates the collections to find any inconsistencies and fixes them if possible, which avoids rebuilding the indexes. See the --repair option for usage and limitations.

Starting in MongoDB 5.0, the validate command and db.collection.validate() helper method return a new corruptRecords field that contains an array of RecordId values for corrupt documents.

Starting in MongoDB 5.0, the setParameter command has a new maxValidateMemoryUsageMB parameter, which sets the maximum memory usage for the validate command.

Starting in MongoDB 5.0, you can set a filter option for the database profiler to determine which operations are profiled and logged. You can use the filter expression in place of the slowms and sampleRate profiler options.

See:

Starting in MongoDB 5.0 (also available starting in 4.4.2, 4.2.12, and 4.0.22), changes made to the database profiler level, slowms, sampleRate, or filter using the profile command or db.setProfilingLevel() wrapper method are recorded in the log file.

Starting in MongoDB 5.0, when auditing is enabled, you may now rotate the server and audit logs independently using the logRotate command. Previously, logRotate would rotate the two logs together.

Starting in MongoDB 5.0, slow operation log messages include a remote field specifying client IP address.

Starting in MongoDB 5.0, the following commands have a let option to define a list of variables. This allows you to improve command readability by separating the variables from the query text.

The update command also has a c field to define a list of variables.

Starting in MongoDB 5.0, the userToDNMapping configuration file option and the --ldapUserToDNMapping command line option for mongod / mongos and mongoldap now map the authenticated username as the LDAP DN by default if an empty mapping document (i.e. an empty string or empty array) is specified to the option. Previously, providing an empty mapping document would cause mapping to fail.

Starting in MongoDB 5.0, the dbStats command outputs these additional statistics:

serverStatus includes the following new fields in its output:

Aggregation Metrics
Replication Metrics
Read Concern Counters
Number of Threaded Connections
Resharding Statistics
Service Executor Metrics
Cursor Metrics
Security Counter

Starting in MongoDB 5.0 (and 4.4.3, 4.2.12, 4.0.23, and 3.6.23), the plan cache will save full plan cache entries only if the cumulative size of the plan caches for all collections is lower than 0.5 GB. When the cumulative size of the plan caches for all collections exceeds this threshold, additional plan cache entries are stored without certain debug information.

The estimated size in bytes of a plan cache entry is available in the output of $planCacheStats.

MongoDB 5.0 introduces the following minimum microarchitecture requirements:

CPU
Minimum Supported Microarchitecture
Intel x86_64
MongoDB 5.0 requires Intel Sandy Bridge or later.
AMD x86_64
MongoDB 5.0 requires AMD Bulldozer or later.
ARM arm64
MongoDB 5.0 requires ARMv8.2-A or later.

MongoDB v5.0 is not supported on x86_64 or arm64 platforms that do not meet these minimum microarchitecture requirements.

MongoDB 5.0 removes support for the following platforms:

  • macOS 10.13
  • RHEL 7 / CentOS 7 / Oracle 7 on the PPC64LE and s390x architectures
  • SLES 12 on the s390x architecture
  • Ubuntu 18.04 on the PPC64LE and s390x architectures

See Supported Platforms for the full list of platforms and architectures supported in MongoDB 5.0.

Some changes can affect compatibility and may require user actions. For a detailed list of compatibility changes, see Compatibility Changes in MongoDB 5.0.

Important
Feature Compatibility Version

To upgrade to MongoDB 5.0 from a 4.4 deployment, the 4.4 deployment must have featureCompatibilityVersion set to 4.4. To check the version:

db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )

To upgrade to MongoDB 5.0, refer to the upgrade instructions specific to your MongoDB deployment:

If you need guidance on upgrading to 5.0, MongoDB offers major version upgrade services to help ensure a smooth transition without interruption to your MongoDB application.

To download MongoDB 5.0, go to the MongoDB Download Center.

Tip
In Version
Issues
Status
5.0.0
SERVER-58171: A Time Series collection's granularity parameter cannot be modified after the collection is created.
Fixed in 5.0.1
5.0.0
SERVER-58392: An ongoing resharding operation may prevent a backup or restore operation from succeeding.
Unresolved

To report an issue, see https://github.com/mongodb/mongo/wiki/Submit-Bug-Reports for instructions on how to file a JIRA ticket for the MongoDB server or one of the related projects.

Give Feedback

On this page