Release Notes for MongoDB 4.2

MongoDB 4.2 Released Aug 13, 2019

Minor Releases

4.2.1 - Oct 18, 2019

Issues fixed:

Distributed Transactions

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 havefeatureCompatibilityVersion 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 havefeatureCompatibilityVersion of 4.2.
    • Clients must use MongoDB drivers updated for MongoDB 4.2
  • Removes the 16MB total size limit for a transaction. In version4.2, MongoDB creates as many oplog entries (maximum size 16MBeach) as necessary to the encapsulate all write operations in atransaction. In MongoDB 4.0, MongoDB creates a single entry forall write operations in a transaction, thereby imposing a 16MBtotal size limit for a transaction.
  • Extends transaction support to deployments whose secondary membersuse the in-memory storage engine. That is,transactions are available for deployments that use the WiredTigerstorage engine for the primary and either the WiredTiger or thein-memory storage engine for the secondarymembers. In MongoDB 4.0, transactions are available for deploymentsthat use the WiredTiger storage engine only.

For more information, see Transactions.

See also

4.2 Transaction Compatibility Changes

Removed MMAPv1 Storage Engine

MongoDB 4.2 removes the deprecated MMAPv1 storage engine.

If your 4.0 deployment uses MMAPv1, you must change the deployment toWiredTiger Storage Engine before upgrading to MongoDB 4.2. For details,see:

MMAPv1 Specific Configuration Options

MongoDB removes the following MMAPv1 specific configurationoptions:

Removed Configuration File SettingRemoved Command-line Option
storage.mmapv1.journal.commitIntervalMs
storage.mmapv1.journal.debugFlagsmongod —journalOptions
storage.mmapv1.nsSizemongod —nssize
storage.mmapv1.preallocDataFilesmongod —noprealloc
storage.mmapv1.quota.enforcedmongod —quota
storage.mmapv1.quota.maxFilesPerDBmongod —quotaFiles
storage.mmapv1.smallFilesmongod —smallfiles
storage.repairPathmongod —repairpath
replication.secondaryIndexPrefetchmongod —replIndexPrefetch

Note

Starting in version 4.2, MongoDB processes will not start withthese options. Remove any MMAPv1 specific configurationoptions if using a WiredTiger deployment.

MMAPv1 Specific Parameters

MongoDB removes the following MMAPv1 parameters:

  • newCollectionsUsePowerOf2Sizes
  • replIndexPrefetch

MMAPv1 Specific Command

MongoDB removes the MMAPv1 specific touch command.

MMAPv1 Specific Options for Binaries, Commands and Methods

MongoDB removes the MMAPv1 specific options:

Removed Commands and Methods

Removed CommandRemoved MethodNotes
groupdb.collection.group()Use db.collection.aggregate() with the$group stage instead.
eval The MongoDB 4.2 mongo shell methodsdb.eval() and db.collection.copyTo() canonly be run when connected to MongoDB 4.0 or earlier.
copydb The corresponding mongo shell helpersdb.copyDatabase() can only be run when connected to MongoDB4.0 or earlier.As an alternative, users can use mongodump andmongorestore (seeCopy/Clone a Database) or write a scriptusing the drivers.
clone The corresponding mongo shell helpersdb.cloneDatabase() can only be run when connected to MongoDB4.0 or earlier.As an alternative, users can use mongodump andmongorestore (seeCopy/Clone a Database) or write a scriptusing the drivers.
geoNear Use db.collection.aggregate() with the$geoNear stage instead.For more information, see Remove Support for the geoNear Command.
parallelCollectionScan
repairDatabasedb.repairDatabase()For more information, see Remove Support for the repairDatabase Command.

Remove maxScan Option

MongoDB removes the deprecated option maxScan for thefind command and the mongo shell helpercursor.maxScan(). Use either the maxTimeMS option for thefind command or the helper cursor.maxTimeMS() instead.

MongoDB Drivers

The following drivers are feature compatible [1] with MongoDB 4.2:

- C 1.15.0- C# 2.9.0- Go 1.1- Java 3.11.0- Node 3.3.0- Perl 2.2.0- Python 3.9.0- Ruby 2.10.0- Scala 2.7.0
[1]Field Level Encryption is available as a beta feature. Currently,the 4.2-compatible Java, Node and Python drivers have support forthe beta feature.

Sharded Clusters

Mutable Shard Key Values

Starting in MongoDB 4.2, you can update a document’s shard key valueunless the shard key field is the immutable _id field. For detailson updating the shard key, see Change a Document’s Shard Key Value.

Before MongoDB 4.2, a document’s shard key field value is immutable.

Backups

mongodump and mongorestorecannot be part of a backup strategy for 4.2+ sharded clustersthat have sharded transactions in progress as these tools cannotguarantee a atomicity guarantees of data across the shards.

For 4.2+ sharded clusters with in-progress sharded transactions, forcoordinated backup and restore processes that maintain the atomicityguarantees of transactions across shards, see:

Balancer State and Autosplit

Starting in MongoDB 4.2:

To disable auto-splitting when the balancer is enabled, you canuse sh.disableAutoSplit().

To enable auto-splitting when the balancer is disabled, you canuse sh.enableAutoSplit().

The mongo methodssh.enableBalancing(namespace) andsh.disableBalancing(namespace) have no affect on theauto-splitting.

mongos Connection Pool

Starting in MongoDB 4.2, MongoDB adds the parameterShardingTaskExecutorPoolReplicaSetMatching thatdetermines the minimum size (can vary during runtime) of themongos instance’s connection pools to each member ofthe sharded cluster.

By default, for each replica set in the sharded cluster (i.e. shardreplica set and config servers), mongos maintainsconnection pools to each replica set secondary that are at leastequal to the size of its connection pool to the primary.

To modify, see ShardingTaskExecutorPoolReplicaSetMatching.

Sharded Collections and Replace Documents

Starting in MongoDB 4.2,

In earlier versions, the operation attempts to target using thereplacement document.

  • For a replace document operation that includes upsert: trueand is on a sharded collection, the filter must include anequality match on the full shard key.

Security Improvements

Resolved Common Vulnerabilities and Exposures

MongoDB 4.2 includes fixes that resolve the following CommonVulnerabilities and Exposures (CVEs):

New TLS Options

MongoDB 4.2 adds TLS options for the mongod, the mongos, and themongo shell to replace the correspondingSSL options (deprecated in 4.2). The new TLS options provideidentical functionality as the deprecated SSL options as MongoDBhas always supported TLS 1.0 and later.

Tip

Most of the new TLS option names are similar to the SSLoption name; e.g. —tlsMode instead of—sslMode. The exceptions are:

See also

New tlsClusterCAFile Option

Deprecated SSL Options

MongoDB 4.2 deprecates the SSL options for the mongod, the mongos, and themongo shell as well as the correspondingnet.ssl Options configuration file options.

Use the new TLS options instead.

New tls Parameters

New ParameterDescription
tlsWithholdClientCertificateAvailable for mongod and mongos,the parameter can be set to true to stop the instance fromsending its TLS certificate when initiating intra-clustercommunications with other mongod ormongos instances. For details, seetlsWithholdClientCertificate.
tlsX509ClusterAuthDNOverrideAvailable for mongod and mongos,the parameter can be set to an alternative certificate DN touse for x.509 membership authentication. For details,see tlsX509ClusterAuthDNOverride.You can use this parameter for a rolling update of certificatesto new certificates that contain a new DN value. SeeRolling Update of x.509 Cluster Certificates that Contain New DN.

New tlsClusterCAFile Option

MongoDB 4.2 adds the—tlsClusterCAFile option/net.tls.clusterCAFile formongod and mongos, which specifies a.pem file for validating the TLS certificate from a clientestablishing a connection. This lets you use separate Certificate Authoritiesto verify the client to server and server to client portions of the TLShandshake.

See also

New TLS Options

Forward Secrecy

Starting in version 4.2 on Linux:

In earlier versions of MongoDB (3.6.14+ and 4.0.3+), MongoDB enablessupport for Ephemeral Elliptic Curve Diffie-Hellman (ECDHE) if, duringcompile time, the Linux platform’s OpenSSL supports automatic curveselection of ECDH parameters.

On Windows and macOS, MongoDB’s support for ECDHE and DH remainunchanged from earlier versions; that is, support is implicit throughthe use of the platform’s respective native TLS/SSL OS libraries.

For more information, see Forward Secrecy.

passwordPrompt()

Starting in version 4.2 of the mongo shell, you canuse the passwordPrompt() method in conjunction withvarious user authentication/management methods/commands to promptfor the password instead of specifying the password directly in themethod/command call. However, you can still specify the passworddirectly as you would with earlier versions of themongo shell.

For example:

  1. db.createUser( {
  2. user:"user123",
  3. pwd: passwordPrompt(), // Instead of specifying the password in cleartext
  4. roles:[ "readWrite" ]
  5. } )

Keyfile Format Change to YAML

Starting in MongoDB 4.2, keyfiles for internal membershipauthentication use YAML format to allow formultiple 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-keykeyfiles that use the text file format.

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

libldap and libldap_r

For MongoDB 4.2 (and 4.0.9) Enterprise binaries linked againstlibldap (such as when running on RHEL), access to thelibldap is synchronized, incurring some performance/latencycosts.

For MongoDB 4.2 (and 4.0.9) Enterprise binaries linked againstlibldap_r, there is no change in behavior from earlier MongoDBversions.

To avoid the automatic synchronization with libldap, you maywish to link to libldap_r. Contact support forassistance.

Encrypted Storage Engine

For encrypted storage engineconfigured with AES256-GCM cipher:

    • Restoring from Hot Backup
    • Starting in 4.2, if you restore from files taken via “hot”backup (i.e. the mongod is running), MongoDBcan detect “dirty” keys on startup and automatically rolloverthe database key to avoid IV (Initialization Vector) reuse.
    • Restoring from Cold Backup
    • However, if you restore from files taken via “cold” backup(i.e. the mongod is not running), MongoDBcannot detect “dirty” keys on startup, and reuse of IV voidsconfidentiality and integrity guarantees.

Starting in 4.2, to avoid the reuse of the keys afterrestoring from a cold filesystem snapshot, MongoDB adds a newcommand-line option —eseDatabaseKeyRollover. When started with the—eseDatabaseKeyRollover option, the mongodinstance rolls over the database keys configured withAES256-GCM cipher and exits.

For more information, see encrypted storage engine and —eseDatabaseKeyRollover.

General Security Enhancements

  • Add serverStatus to the backup built-inrole.

  • To connect a client over TLS/SSL connection, MongoDB 4.2 supportsmatching by IP addresses as well as DNS for Subject Alternative Name(SAN) matching.

For example, a mongod instance’s x.509 certificatehas the following SAN:

  1. X509v3 Subject Alternative Name:
  2. DNS:hostname.example.com, DNS:localhost, IP Address:127.0.0.1

Then, to connect a mongo shell to the instance, youcan specify the host of 127.0.0.1 or the DNS names:

  1. mongo "mongodb:\\127.0.0.1:27017\test" --tls --tlsCAFile /etc/ssl/ca.pem ...
  1. mongo "mongodb:\\hostname.example.com:27017\test" --tls --tlsCAFile /etc/ssl/ca.pem ...
  1. mongo "mongodb:\\localhost:27017\test" --tls --tlsCAFile /etc/ssl/ca.pem ...

In previous versions, MongoDB only supported DNS entries for SANmatching.

  1. mongo "mongodb:\\hostname.example.com:27017\test" --tls --tlsCAFile /etc/ssl/ca.pem ...
  1. mongo "mongodb:\\localhost:27017\test" --tls --tlsCAFile /etc/ssl/ca.pem ...

LDAP Query Template {PROVIDED_USER} Token

Starting in version 4.2, MongoDB Enterprise adds a new token{PROVIDED_USER} that can be used insecurity.ldap.authz.queryTemplate. When used in thetemplate, MongoDB substitutes the supplied username, i.e. before eitherauthentication or LDAP transformation.

Aggregation Improvements

On-Demand Materialized View ($merge Stage)

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, keepexisting documents, fail the operation, process documents with ancustom 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 collectioncan be incrementally updated each time the pipeline is run.

Aggregation Trigonometry Expressions

MongoDB 4.2 adds newtrigonometry 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 toconvert between degree and radian measurements.

NameDescription
$sinReturns the sine of a value that is measured in radians.
$cosReturns the cosine of a value that is measured in radians.
$tanReturns the tangent of a value that is measured in radians.
$asinReturns the inverse sin (arc sine) of a value in radians.
$acosReturns the inverse cosine (arc cosine) of a value in radians.
$atanReturns the inverse tangent (arc tangent) of a value inradians.
$atan2Returns the inverse tangent (arc tangent) of y / x inradians, where y and x are the first and secondvalues passed to the expression respectively.
$asinhReturns the inverse hyperbolic sine (hyperbolic arc sine) of avalue in radians.
$acoshReturns the inverse hyperbolic cosine (hyperbolic arc cosine)of a value in radians.
$atanhReturns the inverse hyperbolic tangent (hyperbolic arctangent) of a value in radians.
$degreesToRadiansConverts a value from degrees to radians.
$radiansToDegreesConverts a value from radians to degrees.

Aggregation Arithmetic Expressions

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

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

Aggregation Regular Expressions (regex) Operators

MongoDB 4.2 adds the following regular expression (regex) patternmatching operators for use in the aggregation pipeline:

OperatorDescription
$regexFindApplies a regular expression (regex) to a string and returnsinformation on the first matched substring.
$regexFindAllApplies a regular expression (regex) to a string and returnsinformation on all matched substrings.
$regexMatchApplies a regular expression (regex) to a string and returnstrue if a match is found and false if a match is notfound.

Prior to MongoDB 4.2, aggregation pipeline can only use the queryoperator $regex in the $match stage.

New Stages

MongoDB 4.2 adds the following new aggregation pipeline stages:

New StageDescription
$mergeWrites the aggregation results to a collection. The$merge stage can incorporate results (mergedocuments, replace documents, keep existing documents, fail theoperation, process documents with an custom update pipeline)into an existing collection.
$planCacheStatsProvides plan cache information for a collection.The $planCacheStats aggregation stage is preferred overthe following methods and commands, which have been deprecated in 4.2:- PlanCache.getPlansByQuery()method/planCacheListPlans command, and- PlanCache.listQueryShapes()method/planCacheListQueryShapes command.See alsoDeprecated Plan Cache Commands/Methods
$replaceWithReplaces the input document with the specified document. Theoperation replaces all existing fields in the input document,including the _id field. The new $replaceWithstage is an alias to the $replaceRoot stage.
$setAdds new fields to documents. The stage outputs documents thatcontains all existing fields from the input documents as well asthe newly added fields. The new $set stage is analias to the $addFields stage.
$unsetExcludes fields from documents. The new $unset stageis an alias to the $project stage that excludesfields.

New Variables

MongoDB 4.2 adds the following new aggregation pipeline variables:

VariableDescription
NOWReturns the current datetime value.
CLUSTER_TIMEReturns the current timestamp value.Only available on replica sets and sharded clusters.

Availability

Starting in MongoDB 4.2, you can use the aggregation pipeline forupdates in:

Commandmongo Shell Methods
findAndModifydb.collection.findAndModify()db.collection.findOneAndUpdate()
updatedb.collection.updateOne()db.collection.updateMany()db.collection.update()

For the updates, the pipeline can consist of the following stages:

Using the aggregation pipeline allows for a more expressive updatestatement, such as expressing conditional updates based on currentfield values or updating one field using the value of another field(s).

See the individual reference pages for details and examples.

See also

Aggregation

Change Stream

startAfter Option for Change Streams

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

Change Streams Resume Tokens

MongoDB 4.2 uses the version 1 (i.e. v1) change streamsresume tokens, introduced inversion 4.0.7.

Starting in MongoDB 4.2, change streams will throw an exception ifthe change stream aggregation pipeline modifies an event’s _id field.

Availability

Starting in MongoDB 4.2, change streams areavailable regardless of the "majority" read concernsupport; that is, read concern majority support can be eitherenabled (default) or disabledto use change streams.

In MongoDB 4.0 and earlier, change streams areavailable only if "majority" read concern support isenabled (default).

Change Stream Pipeline

Starting in MongoDB 4.2, you can use additional stages in thechange stream aggregation pipelineto modify the change stream output (i.e. the event documents):

Starting in MongoDB 4.2, change streams will throw an exception ifthe change stream aggregation pipeline modifies an event’s _id field.

See also

Change Streams Compatibility Changes

Update Enhancements

Update and Aggregation

Starting in MongoDB 4.2, you can use the aggregation pipeline forupdates in:

Commandmongo Shell Methods
findAndModifydb.collection.findAndModify()db.collection.findOneAndUpdate()
updatedb.collection.updateOne()db.collection.updateMany()db.collection.update()

For the updates, the pipeline can consist of the following stages:

Using the aggregation pipeline allows for a more expressive updatestatement, such as expressing conditional updates based on currentfield values or updating one field using the value of another field(s).

See the individual reference pages for details and examples.

Update and Hint

Starting in MongoDB 4.2, the update command and theassociated mongo shell methoddb.collection.update() can accept a hint argument to specifythe index to use. See:

Sharded Collections and Replace Documents

Starting in MongoDB 4.2,

In earlier versions, the operation attempts to target using thereplacement document.

  • For a replace document operation that includes upsert: trueand is on a sharded collection, the filter must include anequality match on the full shard key.

Wildcard Indexes

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

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

  1. { "userMetadata" : { "likes" : [ "dogs", "cats" ] } }
  2. { "userMetadata" : { "dislikes" : "pickles" } }
  3. { "userMetadata" : { "age" : 45 } }
  4. { "userMetadata" : "inactive" }

Administrators want to create indexes to support queries on anysubfield of userMetadata.

A wildcard index on userMetadatacan support single-field queries on userMetadata,userMetadata.likes, userMetadata.dislikes, anduserMetadata.age:

  1. db.userData.createIndex( { "userMetadata.$**" : 1 } )

The index can support the following queries:

  1. db.userData.find({ "userMetadata.likes" : "dogs" })
  2. db.userData.find({ "userMetadata.dislikes" : "pickles" })
  3. db.userData.find({ "userMetadata.age" : { $gt : 30 } })
  4. db.userData.find({ "userMetadata" : "inactive" })

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

Important

Wildcard indexes are not designed to replace workload-based indexplanning. For more information on creating indexes to supportqueries, see Create Indexes to Support Your Queries. Forcomplete documentation on wildcard index limitations, seeWildcard Index Restrictions.

The mongodfeatureCompatibilityVersion must be 4.2 tocreate wildcard indexes. For instructions on setting the fCV, seeSet Feature Compatibility Version on MongoDB 4.2 Deployments.

You can create a wildcard index using the createIndexesdatabase command or its shell helpersdb.collection.createIndex() anddb.collection.createIndexes(). For examples of creatinga wildcard index, see Create a Wildcard Index.

See Wildcard Indexes for complete documentation.

Platform Support

  • MongoDB 4.2 adds support for:
    • Ubuntu 18.04 on ARM64
  • MongoDB 4.2 removes support for:
    • Debian 8
    • 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 Tools

FIPS Mode

Starting in version 4.2, MongoDB removes the —sslFIPSModeoption for the following programs:

The programs will use FIPS compliant connections tomongod/mongos if themongod/mongos instances areconfigured to use FIPS mode.

—uri Option

Starting in version 4.2,

  • For the following command-line tools, if the write concern isspecified in both the —uri connection string and the—writeConcern option, the —writeConcern option overridesthe one in the connection string:
  • For the following command-line tools, if the read preference isspecified in both the —uri connection string and the—readPreference option, the —readPreference optionoverrides the one in the connection string:

Extended JSON v2

Starting in version 4.2:

bsondumpUses Extended JSON v2.0 (Canonicalmode) format.
mongodumpUse Extended JSON v2.0 (Canonical mode) format for themetadata. Requires mongorestore version 4.2+that supports Extended JSON v2.0 (Canonical mode orRelaxed) format.TipIn general, use corresponding versions ofmongodump and mongorestore.That is, to restore data files created with a specificversion of mongodump, use the correspondingversion of mongorestore.
mongoexportCreates output data in Extended JSON v2.0 (Relaxed mode) bydefault.Creates output data in Extended JSON v2.0 (Canonical mode) ifused with —jsonFormat canonical.
mongoimportExpects import data to be in Extended JSON v2.0 (eitherRelaxed or Canonical mode) by default.Can recognize data that is in Extended JSON v1.0 format if the option—legacy is specified.TipIn general, the versions of mongoexport andmongoimport should match. That is, to importdata created from mongoexport, you should usethe corresponding version of mongoimport.

For details on MongoDB extended JSON v2, seeMongoDB Extended JSON (v2).

See also

—query Options

mongofiles

The mongofiles command get_id and delete_id can acceptboth ObjectId or non-ObjectId values for the _id.

Bulk Operations for mongoimport and mongorestore

mongoimport

Starting in version 4.2:

  • mongoimport uses maximum batch size of 100,000 toperform bulk insert/upsert operations.
  • mongoimport by default,continues when it encounters duplicate key and documentvalidation errors. To ensure that the program stops on these errors, specify —stopOnError.
  • Specifying —maintainInsertionOrder for mongoimport:
    • Maintains document insertion order using ordered bulk writeoperations; i.e. both the batch order and document order within the batches are maintained. In earlier versions, only the batch order is maintained; document order within batches are not maintained.
    • Enables —stopOnError and setsnumInsertionWorkers to1.
mongorestore

Starting in version 4.2:

Lock Optimization for Specific DDL Operations

Starting with MongoDB 4.2, the following operations take anexclusive collection lock instead of an exclusive database lock:

CommandsMethods
createdb.createCollection()db.createView()
createIndexesdb.collection.createIndex()db.collection.createIndexes()
dropdb.collection.drop()
dropIndexesdb.collection.dropIndex()db.collection.dropIndexes()
renameCollectiondb.collection.renameCollection()

Prior to MongoDB 4.2, these operations took an exclusive lock on thedatabase, blocking all operations on the database and its collectionsuntil the operation completed.

In earlier versions, get_id and delete_id can only acceptObjectId values for the _id.

Monitoring

Starting in version 4.2, the Storage Node Watchdog is available in both the MongoDB Communityedition and the MongoDB Enterprise edition.

In earlier versions, the feature is available in the MongoDB Enterpriseedition only.

Flow Control

MongoDB 4.2 introduces a flow control mechanism to control the rate atwhich the primary applies its writes in order to keep themajority committedlag under a specified maximum value.

Flow control is enabled by default.

Note

For flow control to engage, the replica set/sharded cluster musthave: featureCompatibilityVersion (FCV) of4.2 and read concern majority enabled. That is, enabled flowcontrol has no effect if FCV is not 4.2 or if read concernmajority is disabled.

For more information, see Replication Lag and Flow Control.

Logging and Diagnostics

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. Inprevious versions, MongoDB log messages only specified D forDebug level.

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

  1. ... ACCESS [repl writer worker 5] Unsupported modification to roles collection ...

Previously, the syslog message text didnot include the component. Forexample:

  1. ... [repl writer worker 1] Unsupported modification to roles collection ...
  • MongoDB 4.2 adds a usedDisk indicator to the profiler logmessages anddiagnostic log messages for theaggregate operation. The usedDisk indicates whetherany stages of an aggregate operation wrote data totemporary files due to memory restrictions. For more information onaggregation 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 takelonger than the slow operation threshold to apply. These messages arelogged for the secondaries under theREPL component with the text applied op: <oplog entry> took<num>ms.

  1. 2018-11-16T12:31:35.886-0500 I REPL [repl writer worker 13] applied op: command { ... }, took 112ms

The slow oplog application logging on secondaries are:

currentOp

MongoDB 4.2 adds a new option idleCursors to the$currentOp aggregation stage in order to return informationon idle cursors.

In addition, MongoDB 4.2 adds the following new fields to the documentsreturned from the $currentOp aggregation stage,currentOp command, and db.currentOp() helper:

$currentOpcurrentOp/db.currentOp()Description
$currentOp.typecurrentOp.typeSpecifies whether the reported operation is an op,idleSession, or idleCursor.
$currentOp.cursorcurrentOp.cursorSpecifies cursor details. Available when returning getmoreoperations or idleCursor information.
$currentOp.effectiveUserscurrentOp.effectiveUsersSpecifies users associated with the operation.
$currentOp.prepareReadConflictscurrentOp.prepareReadConflictsSpecifies the number of times the current operation had to waitfor a prepared transaction with a write to commit or abort.
$currentOp.runBycurrentOp.runBySpecifies users that are impersonating the effective users forthe operation.
$currentOp.writeConflictscurrentOp.writeConflictsSpecifies the number of times the current operation conflictedwith another write operation.

See also 4.2 current op compatibility changes

serverStatus Metrics

Starting in MongoDB 4.2, the serverStatus command and themongo shell method db.serverStatus() includethe following output changes:

Updates toChanges
shardingStatisticsAdded new fields:- shardingStatistics.countDocsClonedOnRecipient- shardingStatistics.countDocsClonedOnDonor- shardingStatistics.countDocsDeletedOnDonor- shardingStatistics.countRecipientMoveChunkStarted- shardingStatistics.countDonorMoveChunkLockTimeout
metrics.repl.network:Added new fields:- metrics.repl.network.notMasterLegacyUnacknowledgedWrites- metrics.repl.network.notMasterUnacknowledgedWrites
metrics.replAdded new metrics.repl.stepDown metrics:- metrics.repl.stepDown.userOperationsKilled- metrics.repl.stepDown.userOperationsRunning
transactions- Now available for mongos (previously only formongod)- Added new fields for mongod instances: - transactions.totalPrepared - transactions.totalPreparedThenCommitted - transactions.totalPreparedThenAborted - transactions.currentPrepared
logicalSessionRecordCacheAdded new field logicalSessionRecordCache.sessionCatalogSize
locksSeparate ParallelBatchWriterMode from Globallock information.Add ReplicationStateTransition lock information.

Replica Set Status Metrics

Starting in version MongoDB 4.2, replSetGetStatus and itsmongo shell helper rs.status() return:

New ISODate-Formatted Date String FieldCorresponding Optime FieldlastCommittedWallTimelastCommittedOpTimereadConcernMajorityWallTimereadConcernMajorityOpTimelastAppliedWallTimeappliedOpTimelastDurableWallTimedurableOpTime

MongoDB 4.2 deprecates the fieldlastStableCheckpointTimestamp.

Lock Diagnostics Reporting

Starting in version 4.2, MongoDB reports onReplicationStateTransition lock information.

In addition, MongoDB 4.2 separates ParallelBatchWriterMode lockinformation from Global lock information. Earlier MongoDB versionsreport ParallelBatchWriterMode lock information as partof Global locks.

For operations that report on lock information, see:

collStats Improvements

Starting in MongoDB 4.2, the $collStats aggregation, thecollStats command, and the mongo shellhelper db.collection.stats return information on indexes thatare currently being built.

For details, see:

Starting in MongoDB 4.2, the $collStats aggregation, thecollStats command, and the mongo shellhelper db.collection.stats return the scaleFactor used toscale the various size data.

dbStats Improvements

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

General Improvements

Externally Sourced Values for Configuration Files

MongoDB supports usingexpansion directives in configurationfiles to load externally sourced values. Expansion directives canload values for specificconfiguration file optionsor load theentire configuration file.

The following expansion directives are available:

Expansion DirectiveDescription
__restAllows users to specify a REST endpoint as the external sourcefor configuration file options or the full configuration file.
__execAllows users to specify a shell or terminal command as theexternal source for configuration file options or thefull configuration file.

For complete documentation, see Externally Sourced Configuration File Values.

outputConfig Option

MongoDB 4.2 adds the —outputConfigoption for mongod and mongos. The optionoutputs to stdout the mongod/mongosinstance’s configuration, in YAML format.

If the configuration uses any Externally Sourced Configuration File Values, theoption returns the resolved value for those options.

Warning

This may include any configured passwords or secrets previouslyobfuscated through the external source.

For usage examples, see:

Remove Index Key Size Limit

Starting in MongoDB 4.2, for featureCompatibilityVersion set to "4.2" or greater, MongoDB removes theIndex Key Limit. For fCV set to "4.0", the limit stillapplies.

See also

4.2 Indexes Compatibility Changes

Remove Index Name Length Limit

Starting in version 4.2, for featureCompatibilityVersion set to "4.2" or greater, MongoDB removes theIndex Name Length limit of 127 byte maximum. In previousversions or MongoDB versions withfeatureCompatibilityVersion (fCV) set to"4.0", index names must fall within thelimit.

See also

4.2 Indexes Compatibility Changes,4.2 Feature Compatibility

Improvements to dropIndexes

Drop multiple indexes

Starting in MongoDB 4.2, you can specify multiple indexes to thedropIndexes command and its mongo shellhelper db.collection.dropIndexes(). To specify multipleindexes to drop, pass an array of index names todropIndexes/db.collection.dropIndexes().

Starting in MongoDB 4.2, the dropIndexes or its shell helpers dropIndex() and dropIndexes() operation only killsqueries that are using the index being dropped. This may includequeries considering the index as part ofquery planning.

Prior to MongoDB 4.2, dropping an index on acollection would kill all open queries on the collection.

zstd Availability

Starting in version 4.2, MongoDB supports zstd for:

bulkWrite() Error Handling inside Transactions

Starting in MongoDB 4.2, if a db.collection.bulkWrite()operation encounters an error inside a transaction, the method throws a BulkWriteException (same as outside a transaction).

In 4.0, if the bulkWrite operation encounters an error inside atransaction, the error thrown is not wrapped as aBulkWriteException.

Inside a transaction, the first error in a bulk write causes theentire bulk write to fail and aborts the transaction, even if thebulk write is unordered.

Query Plan Improvements

Plan Cache States

Starting in MongoDB 4.2, the cache entry is associated with a state:

Associating states with entries helps reduce the likelihood thatsub-optimal cache entries remain in the cache. For more information,see Query Plans.

queryHash and planCacheKey

    • queryHash
    • To help identify slow queries with the same query shape,starting in MongoDB 4.2, each query shape is associated witha queryHash. The queryHash is ahexadecimal string that represents a hash of the query shape andis dependent only on the query shape.

Note

As with any hash function, two different query shapes may resultin the same hash value. However, the occurrence of hashcollisions between different query shapes is unlikely.

planCacheKey is a hash of the key for the plan cache entryassociated with the query.

Note

Unlike the queryHash, the planCacheKey is a function ofboth the query shape and the currently available indexes for theshape. That is, if indexes that can support the query shape areadded/dropped, the planCacheKey value may change whereas thequeryHash value would not change.

See also

planCacheKey

The fields are also available in operations that return informationabout the query plan cache:

See also

Deprecated Plan Cache Commands/Methods

$regex and $not

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

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

Kill Own Cursors

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

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

New Parameters

MongoDB 4.2 adds the parameter replBatchLimitBytes toconfigure the maximum oplog application batch size. The parameter isalso available starting in MongoDB 4.0.10.

Retryable Writes on Certain Single-Document Upserts

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

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

db.dropDatabase() and Write Concern

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

dropConnections

The dropConnections command drops themongod/mongos instance’s outgoingconnections to the specified hosts. The dropConnectionsmust be run against the admin database.

Client Disconnection

For the following operations, if the issuing client disconnects beforethe operation completes, MongoDB marks the following operations for termination(e.g. killOp on the operation):

Commandmongo Shell MethodNotes
aggregatedb.collection.aggregate()Behavior only applies if the pipeline does not include $out and $merge
authenticatedb.auth
countdb.collection.countdb.collection.countDocumentsdb.collection.estimatedDocumentCount
distinctdb.collection.distinct
finddb.collection.finddb.collection.findOne
getnonce
isMaster
listCollectionsdb.getCollectionInfosdb.getCollectionNames
listDatabases
listIndexesdb.collection.getIndexes

Startup Warnings

In-Memory Storage Engines

Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica setmember uses the in-memory storage engine(voting or non-voting) but the replica set haswriteConcernMajorityJournalDefault set to true, thereplica set member logs a startup warning.

mongo Shell

Starting in MongoDB 4.2 (and 4.0.13), the mongo shell displays awarning message when connected to non-genuine MongoDB instances asthese instances may behave differently from the official MongoDBinstances; e.g. missing or incomplete features, different featurebehaviors, etc.

Map-Reduce

Starting in version 4.2, MongoDB deprecates:

  • The map-reduce option to create a new sharded collection as wellas the use of the sharded option formap-reduce. To output to a sharded collection, create the shardedcollection first. MongoDB 4.2 also deprecates the replacement ofan existing sharded collection.
  • The explicit specification of nonAtomic: false option.

Rollback Time Limit

Starting in MongoDB 4.2, the rollback time limit is calculated betweenthe first operation after the common point and the last point in theoplog for the member to roll back.

In MongoDB 4.0, the rollback time limit is calculated between thecommon point and the last point in the oplog for the member to rollback.

For more information, see Rollback Elapsed Time Limitations.

isInteractive()

MongoDB 4.2 adds a new mongo shell methodisInteractive() that returns a boolean indicating whether themongo shell is running in interactive or script mode.

Change to explain Output

Starting in MongoDB 4.2, the explain output can include a newoptimizedPipeline field. For details,refer to optimizedPipeline.

Change to isMaster Output

Starting in MongoDB 4.2, the output for isMaster, and thedb.isMaster() helper method, returns theconnectionId for themongod/mongos instance’s connection tothe client.

Optimized Index Builds

MongoDB index builds against a populated collection require an exclusiveread-write lock against the collection. Operations that require a reador write lock on the collection must wait until themongod releases the lock. MongoDB uses an optimized buildprocess that only holds the exclusive lock at the beginning and end ofthe index build. The rest of the build process yields to interleavingread and write operations.

For feature compatibility version (fcv) 4.2,MongoDB 4.2 index builds fully replace the index build processessupported in previous MongoDB versions. MongoDB ignores thebackground index build option if specified tocreateIndexes or its shell helperscreateIndex() andcreateIndexes().

Requires featureCompatibilityVersion 4.2

For MongoDB clusters upgraded from 4.0 to 4.2, you must set thefeature compatibility version (fcv) to 4.2to enable the optimized build process. For more information onsetting the fCV, see setFeatureCompatibilityVersion.

MongoDB 4.2 clusters running with fCV 4.0 only support 4.0 indexbuilds.

For complete documentation on the index build process, seeIndex Builds on Populated Collections.

Changes Affecting Compatibility

Some changes can affect compatibility and may require user actions. Fora detailed list of compatibility changes, seeCompatibility Changes in MongoDB 4.2.

Upgrade Procedures

Feature Compatibility Version

To upgrade, the 4.0 instances must havefeatureCompatibilityVersion set to 4.0. To check the version:

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

For specific details on verifying and setting thefeatureCompatibilityVersion as well as information on otherprerequisites/considerations for upgrades, refer to the individualupgrade instructions:

If you need guidance on upgrading to 4.2, MongoDB offers major versionupgrade servicesto help ensure a smooth transition without interruption to your MongoDB application.

Download

To download MongoDB 4.2, go to the MongoDB Download Center

See also

Known Issues

In VersionIssuesStatus
4.2.0SERVER-43075: Missing storage.journal.commitIntervalMsFixed in 4.2.1

Report an Issue

To report an issue, seehttps://github.com/mongodb/mongo/wiki/Submit-Bug-Reports forinstructions on how to file a JIRA ticket for the MongoDB server or oneof the related projects.