Release Notes for MongoDB 4.2 Release Candidate¶


MongoDB 4.2 is currently in development.

Warning

While the 4.2 release candidates are available, these versions of MongoDB are for testing purposes only and not for production use.

Distributed Transactions and Multi-Document Transactions

Starting in MongoDB 4.2, the two terms are synonymous. Distributed transactions refer to multi-document transactions on sharded clusters and replica sets. Multi-document transactions (whether on sharded clusters or replica sets) are also known as distributed transactions starting in MongoDB 4.2.

In version 4.2, MongoDB introduces distributed transactions. Distributed transactions:

  • Adds support for multi-document transactions on sharded clusters.
    • All members of the 4.2 sharded clusters must have featureCompatibilityVersion of 4.2.
    • Clients must use MongoDB drivers updated for MongoDB 4.2
  • Incorporates the existing support for transactions on replica sets.
    • All members of the 4.2 replica set must have featureCompatibilityVersion of 4.2.
    • Clients must use MongoDB drivers updated for MongoDB 4.2
  • Removes the 16MB total size limit for a transaction. In version 4.2, MongoDB creates as many oplog entries (maximum size 16MB each) as necessary to the encapsulate all write operations in a transaction. In MongoDB 4.0, MongoDB creates a single entry for all write operations in a transaction, thereby imposing a 16MB total size limit for a transaction.
  • Extends transaction support to deployments whose secondary members use the in-memory storage engine. That is, transactions are available for deployments that use the WiredTiger storage engine for the primary and either the WiredTiger or the in-memory storage engine for the secondary members. In MongoDB 4.0, transactions are available for deployments that use the WiredTiger storage engine only.

For more information, see Transactions.

MongoDB 4.2 adds tlsWithholdClientCertificate to setParameter for mongod and mongos. Set to true to stop the mongod acting as a client during intra-cluster communication from sending its configured TLS certificate to the remote mongod. Use with settings allowing inbound connections without certificates.

MongoDB 4.2 adds the --tlsClusterCAFile option/net.tls.clusterCAFile for mongod and mongos, which specifies a .pem file for validating the TLS certificate from a client establishing a connection. This lets you use separate Certificate Authorities to verify the client to server and server to client portions of the TLS handshake.

Starting in version 4.2 of the mongo shell, you can use the passwordPrompt() method in conjunction with various user authentication/management methods/commands to prompt for the password instead of specifying the password directly in the method/command call. However, you can still specify the password directly as you would with earlier versions of the mongo shell.

For example:

Starting in MongoDB 4.2, keyfiles for internal membership authentication use YAML format to allow for multiple keys in a keyfile. The YAML format accepts content of:

  • a single key string (same as in earlier versions),
  • multiple key strings (each string must be enclosed in quotes), or
  • sequence of key strings.

The YAML format is compatible with the existing single-key keyfiles that use the text file format.

The new format allows for rolling upgrade of the keys without downtime. See Rotate Keys for Replica Sets and Rotate Keys for Sharded Clusters.

General Security Enhancements

MongoDB 4.2 adds the $merge aggregation stage.

With the new stage you can:

  • Can output to a collection in the same or different database.
  • Can incorporate results (merge documents, replace documents, keep existing documents, fail the operation, process documents with an custom update pipeline) into an existing collection.
  • Can output to an existing sharded collection.

The new stage allows users to create on-demand materialized views, where the content of the output collection can be incrementally updated each time the pipeline is run.

MongoDB 4.2 adds new trigonometry expressions for use in aggregation pipelines.

Trigonometry expressions perform trigonometric operations on numbers. Values that represent angles are always input or output in radians. Use $degreesToRadians and $radiansToDegrees to convert between degree and radian measurements.

Name Description
$sin Returns the sine of a value that is measured in radians.
$cos Returns the cosine of a value that is measured in radians.
$tan Returns the tangent of a value that is measured in radians.
$asin Returns the inverse sin (arc sine) of a value in radians.
$acos Returns the inverse cosine (arc cosine) of a value in radians.
$atan Returns the inverse tangent (arc tangent) of a value in radians.
$atan2 Returns the inverse tangent (arc tangent) of y / x in radians, where y and x are the first and second values passed to the expression respectively.
$asinh Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians.
$acosh Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians.
$atanh Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians.
$degreesToRadians Converts a value from degrees to radians.
$radiansToDegrees Converts a value from radians to degrees.

MongoDB 4.2 adds the $round aggregation expression. Use $round to round numerical values to a specific digit or decimal place.

MongoDB 4.2 adds expanded functionality and new syntax to $trunc. Use $trunc with the new syntax to truncate numerical values to a specific digit or decimal place.

MongoDB 4.2 adds startAfter as an option for Change Streams, which starts a new change stream after the event indicated by a resume token. With this option, you can start a change stream from an invalidate event, thereby guaranteeing no missed notifications after the previous stream was invalidated.

MongoDB 4.2 uses the version 1 (i.e. v1) change streams resume tokens, introduced in version 4.0.7.

MongoDB 4.2 introduces wildcard indexes for supporting queries against fields whose names are unknown or arbitrary.

Consider an application that captures user-defined data under the userMetadata field and supports querying against that data:

{ "userMetadata" : { "likes" : [ {"dogs", "cats" ] } }
{ "userMetadata" : { "dislikes" : "pickles" } }
{ "userMetadata" : { "age" : 45 } }
{ "userMetadata" : "inactive" }

Administrators want to create indexes to support queries on any subfield of userMetadata. A wildcard index on userMetadata can support single-field queries on userMetadata, userMetadata.likes, userMetadata.dislikes, and userMetadata.hobbies:

# These queries can use the wildcard index db.userData.find({ "userMetadata.likes" : "dogs" })
db.userData.find({ "userMetadata.dislikes" : "pickles" })
db.userData.find({ "userMetadata.age" : { $gt : 30 } })
db.userData.find({ "userMetadata" : "inactive" })

A non-wildcard index on userMetadata can only support queries on values of userMetadata.

The mongod featureCompatibilityVersion must be 4.2 to create wildcard indexes. For instructions on setting the fCV, see Set Feature Compatibility Version on MongoDB 4.2 Deployments.

You can create a wildcard index using the createIndexes database command or its shell helpers db.collection.createIndex() and db.collection.createIndexes(). For examples of creating a wildcard index, see Create a Wildcard Index.

  • MongoDB 4.2 adds support for:
  • MongoDB 4.2 removes support for:
    • Ubuntu 14.04
    • Ubuntu 16.04 ARM64 for MongoDB Community Edition
    • Ubuntu 16.04 POWER/PPC64LE (Also removed in version 3.6.13 and 3.4.21)
    • macOS 10.11

See Supported Platforms.

MongoDB 4.2 adds the --outputConfig option for mongod and mongos, which outputs the resolved YAML configuration document to stdout and halts the server instance.

MongoDB supports using expansion directives in configuration files to load externally sourced values. Expansion directives can load values for specific configuration file options or load the entire configuration file.

The following expansion directives are available:

Expansion Directive Description
__rest Allows users to specify a REST endpoint as the external source for configuration file options or the full configuration file.
__exec Allows users to specify a shell or terminal command as the external source for configuration file options or the full configuration file.

For complete documentation, see Externally Sourced Configuration File Values.

Logging

  • Added INITSYNC component to log messages.

  • Added ELECTION component to log messages.

  • For debug messages, include the verbosity level (i.e. D[1-5]). For example, if verbosity level is 2, MongoDB logs D2. In previous versions, MongoDB log messages only specified D for Debug level.

  • When logging to syslog, the format of the message text includes the component. For example:

    Previously, the syslog message text did not include the component. For example:

  • MongoDB 4.2 adds a usedDisk indicator to the profiler log messages and diagnostic log messages for the aggregate operation. The usedDisk indicates whether any stages of an aggregate operation wrote data to temporary files due to memory restrictions. For more information on aggregation memory restrictions, see Memory Restrictions.

  • Starting in version 4.2 (also available starting in 4.0.6), secondary members of a replica set now log oplog entries that take longer than the slow operation threshold to apply. These messages are logged for the secondaries under the REPL component with the text applied op: <oplog entry> took <num>ms.

    The slow oplog application logging on secondaries are:

    For more information on setting the slow operation threshold, see

  • Starting in MongoDB 4.2, the getLog command truncates any event that contains more than 1024 characters. In earlier versions, getLog truncates after 512 characters.

  • Starting in MongoDB 4.2 (and in 4.0.9), for slow operations, the profiler entries and diagnostic log messages include storage information.

  • Starting in MongoDB 4.2, the profiler entries and the diagnostic log messages (i.e. mongod/mongos log messages) for read/write operations include:

    • queryHash to help identify slow queries with the same query shape.
    • planCacheKey to provide more insight into the query plan cache for slow queries.

    See queryHash and planCacheKey.

serverStatus Metrics

Starting in MongoDB 4.2 (and 4.0.7), $not operator can perform logical NOT operation on $regex operator expressions as well as on regular expression objects (i.e. /pattern/).

In 4.0 and earlier versions, you could use $not operator with regular expression objects (i.e. /pattern/) but not with $regex operator expressions.

Starting in MongoDB 4.2, users can always kill their own cursors, regardless of whether the users have the privilege to killCursors. As such, the killCursors privilege has no effect starting in MongoDB 4.2.

In MongoDB 4.0, users required the killCursors privilege in order to kill their own cursors.

Starting in MongoDB 4.2, the dbStats command, and the mongo shell helper db.stats() return the scaleFactor used to scale the various size data.

MongoDB 4.2 adds the parameter replBatchLimitBytes to configure the maximum oplog application batch size. The parameter is also available starting in MongoDB 4.0.10.

MongoDB 4.2 will retry certain single-document upserts (update with upsert: true and multi: false) that encounter a duplicate key exception. See Duplicate Key Errors on Upsert for conditions.

Prior to MongoDB 4.2, MongoDB would not retry upsert operations that encountered a duplicate key error.

Starting in MongODB 4.2, the mongo shell method db.dropDatabase() can take an optional write concern document.