All Products
Search
Document Center

:Compatibility changes in MongoDB 4.0

Last Updated:Apr 16, 2025

This topic describes the compatibility changes in MongoDB 4.0.

To view the official MongoDB compatibility change documentation, visit Legacy Documentation.

Deprecation of MONGODB-CR

Starting from MongoDB 4.0, MongoDB no longer supports the deprecated MONGODB-CR authentication mode.

Starting from MongoDB 3.0, MongoDB no longer allows you to create an MONGODB-CR user, unless your deployment is upgraded from V2.6 or earlier and does not upgrade the authentication mode for your original MONGODB-CR user.

If your deployment still uses the MONGODB-CR mode to store user credentials, you must upgrade the mode to Salted Challenge Response Authentication Mechanism (SCRAM) before upgrading the deployment to MongoDB 4.0.

Removal of the authSchemaUpgrade command

MongoDB 4.0 removes the authSchemaUpgrade command. This command is used in MongoDB 3.0 to 3.6 to upgrade MONGODB-CR users to SCRAM users.

Removal of MongoDB-CR support from db.copyDatabase() and copydb

The db.copyDatabase() method and the copydb command cannot copy data from a mongod instance that enforces the MONGODB-CR authentication mode.

In conjunction with this change, MongoDB 4.0 removes the copydbgetnonce command.

Deprecation of MMAPv1

Starting from MongoDB 4.0, MongoDB deprecates the MMAPv1 storage engine. You must migrate your instance to the WiredTiger storage engine.

Limits on X.509 authentication certificates

Starting from MongoDB 4.0, if you specify --sslAllowInvalidCertificates or net.ssl.allowInvalidCertificates: true (renamed to --tlsAllowInvalidateCertificates or net.tls.allowInvalidCertificates: true in MongoDB 4.2) when using x.509 authentication, an invalid certificate is sufficient only to establish a TLS/SSL connection but is insufficient for authentication.

To resolve this issue, update an invalid certificate to a valid certificate (such as one signed by a trusted CA) or use net.ssl.CAFile to specify a custom CA.

Replica set instances

Removal of replica set pv0

MongoDB 4.0 removes the deprecated replica set protocol version 0 (pv0). Before upgrading your protocol version, first upgrade it to pv1. Sample code:

cfg = rs.conf();
cfg.protocolVersion=1;
rs.reconfig(cfg);

Additionally, we recommend that you increase settings.catchUpTimeoutMillis to reduce the rollback probability with the w:1 write concern configuration.

Removal of master-slave replication

MongoDB 4.0 no longer supports master-slave replication. If your deployment is still using this mode, you must convert the deployment to the replica set (CSRS ) mode.

Logging for replica set instances

Starting from MongoDB 4.0, you cannot disable the logging feature for replica set members using the WiredTiger storage engine. This means that you cannot specify --nojournal or storage.journal.enabled: false.

Index build for replica set instances

When using --replSet or replication.replSetName to configure a replica set instance, you cannot specify --noIndexBuildRetry or storage.indexBuildRetry. This means that you cannot specify --noIndexBuildRetry or storage.indexBuildRetry for a mongod instance that is a member of a replica set instance.

Rollback limits

MongoDB 4.0 removes the rollback data volume limit of 300 MB and introduces a configurable parameter rollbackTimeLimitSecs.In MongoDB 4.0, the default rollback time limit is 1 day. Prior to MongoDB 4.0, the rollback time limit is fixed to 30 minutes.

Sharded cluster instances

mongos uses the "majority" write concern level in the following operations that affect sharded cluster metadata.

Command

Method

Description

addShard

sh.addShard()

create

db.createCollection()

drop

db.collection.drop()

dropDatabase

db.dropDatabase()

Changed in MongoDB 3.6.

enableSharding

sh.enableSharding()

movePrimary

renameCollection

db.collection.renameCollection()

shardCollection

sh.shardCollection()

removeShard

setFeatureCompatibilityVersion

MongoDB 4.0 feature compatibility

Some features in MongoDB 4.0 require V4.0 binary files and featureCompatibilityVersion set to 4.0. The following features are included:

  • SCRAM-SHA-256

  • New type conversion operators (including $toBool and $toInt) and enhancements

  • Multi-document transactions

  • $dateToString option changes

  • New change stream methods

  • Change stream resume token data type changes

Other changes

  • Sharded cluster instances support geospatial query operators $near and $nearSphere.

  • For the create command and the mongo shell method db.createCollection(), when creating collections in databases other than the local database, you cannot set the autoIndexId option to false.

  • If you enable authentication and run the listDatabases command without the listDatabases operation permissions, MongoDB returns a list of all database on which you have the find operation permissions. Prior to MongoDB 4.0, If you run the command without the listDatabases operation permissions, MongoDB returns Unauthorized.

  • The default value of taskExecutorPoolSize is changed from 0 to 1. On Linux, to restore the previous behavior of a V4.0 deployment, set taskExecutorPoolSize to 0 and AsyncRequestsSenderUseBaton to false.

  • MongoDB 4.0 does not allow you to set transportLayer and net.transportLayer to legacy for mongod and mongos instances. transportLayer is set to asio by default and cannot be changed.

  • Starting from MongoDB 4.0, the reIndex command and its db.collection.reIndex() take a global exclusive lock and block other operations until completion.

  • If the values of fields other than year, isoYear, and timezone exceed their valid ranges, $dateFromParts subtracts the difference from other date parts to calculate the date. Prior to MongoDB 4.0, values that exceed the valid ranges cause an error.

  • The behavior of a killCursors operation is changed. Prior to MongoDB 4.0, if obtaining a cursor ID, you can kill any cursor. Starting from MongoDB 4.0, killCursors allows you to kill any existing cursor. If you do not have permissions to kill a cursor, killCursors returns an error.

  • MongoDB 4.0 adds a killAnyCursor operation that grants the permissions to kill any cursor for a specified collection.

  • Starting from MongoDB 4.0, when you attempt to connect a mongos instance to another instance with a higher feature compatibility version (fCV), the mongos instance may crash. For example, a mongos instance of MongoDB 4.0 cannot connect to a sharded cluster instance with fCV set to 4.2. However, if the fCV of the sharded cluster instance remains 4.0, the mongos instance can normally connect to another instance.

  • Starting from MongoDB 4.0, MongoDB resolves localhost IP addresses based on specified settings, rather than assuming 127.0.0.1.

cursor.min() and cursor.max()

If you use max() and min() to specify a range, the boundary specified by max() must be greater than that specified by min().

In earlier versions, boundaries could be equal, but no index entries are scanned, resulting in an empty result set.

Disabled TLS 1.0

MongoDB binary files (mongod, mongos, and mongo) disable TLS 1.0 encryption by default for systems that support TLS 1.1+.

To forcibly enable TLS 1.0:

  • For mongod instances, specify net.ssl.disabledProtocols: none in the configuration file, or use the command line parameter --sslDisabledProtocols none.

  • For mongos instances, use net.ssl.disabledProtocols: none or --sslDisabledProtocols none.

  • For the mongo shell, add the --sslDisabledProtocols none parameter.

    The --sslDisabledProtocols parameter can be used in the following mongo shell versions:

    • MongoDB 4.0+

    • MongoDB 3.6.5+

    • MongoDB 3.4.15+

On macOS, if using the mongo shell of MongoDB 3.6.4 or earlier to connect to a sharded cluster instance of MongoDB 4.0+, you must explicitly enable TLS 1.0.

Mongo shell

show collections

In the mongo shell, the show collections command is equivalent to:

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )
  • For users with permissions, all non-system collections in their databases are displayed.

  • For users without permissions, only accessible collections are displayed.

If the mongo shell of MongoDB 4.0 connects to a MongoDB database that runs a version earlier than V4.0 does not support the authorizedCollections and nameOnly parameters:

  • Users must have the listCollection permission to execute the command.

  • If users without permissions run the command, MongoDB include approximate results in the authenticatedUserPrivileges field returned by connectionStatus.

db.getCollectionNames()

In the mongo shell, the db.getCollectionNames() method is equivalent to:

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )
  • For users with access permissions, this method lists all collections in a database.

  • For users without access permissions, this method only lists collections on which they have permissions.

Removal of binary files and deprecated fields or commands

mongoperf

MongoDB 4.0 removes the mongoperf binary file.

copydb and clone commands

MongoDB 4.0 deprecates the copydb and clone commands, along with the mongo shell helper functions db.copyDatabase() and db.cloneDatabase().

Instead, use mongodump and mongorestore (along with the --nsFrom and --nsTo parameters of mongorestore options) or a driver for writing a script.

For example, to copy the test database to the examples database on the same instance, perform the following steps:

  1. Use mongodump to dump the test database to an archived file named mongodump-test-db.

    mongodump --archive="mongodump-test-db" --db=test
  2. Use mongorestore along with the --nsFrom and --nsTo parameters to restore data from the archived file.

    mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'
Note

You can add parameters as needed, such as --uri, --host, --username.

Alternatively, instead of using the archived file, utilize mongodump to dump the test database to the standard output stream and then pipe it into mongorestore.

mongodump --archive --db=test | mongorestore --archive  --nsFrom='test.*' --nsTo='examples.*'

Parameters

The deprecated logUserIds parameter is removed.

$isolated operator

MongoDB no longer supports the $isolated operator. If you have indexes or views containing the $isolated operator, recreate them without this operator before upgrading.

geoNear command

MongoDB deprecates the geoNear command. Use the following commands instead:

  • $geoNear aggregation stage

  • $near query operator

  • $nearSphere query operator

maxScan option

MongoDB deprecates the maxScan option and the mongo shell method cursor.maxScan(). Use maxTimeMS or the mongo shell method cursor.maxTimeMS() instead.

Output field changes

  • The following fields in the replSetGetStatus return result are deprecated:

    • replSetGetStatus.syncingTo

    • replSetGetStatus.members[n].syncingTo

    Use replSetGetStatus.replSetGetStatus.syncSourceHost and replSetGetStatus.members[n].syncSourceHost instead.

  • The $currentOp aggregation stage, currentOp command, and db.currentOp() helper function no longer return the threadId field in their output.

  • The asserts.warning field of serverStatus always returns 0.