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 |
|
| |
|
| |
|
| |
|
| Changed in MongoDB 3.6. |
|
| |
| ||
|
| |
|
| |
| ||
|
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
$toBooland$toInt) and enhancementsMulti-document transactions
$dateToStringoption changesNew change stream methods
Change stream resume token data type changes
Other changes
Sharded cluster instances support geospatial query operators
$nearand$nearSphere.For the
createcommand and the mongo shell methoddb.createCollection(), when creating collections in databases other than thelocaldatabase, you cannot set theautoIndexIdoption tofalse.If you enable authentication and run the
listDatabasescommand without thelistDatabasesoperation permissions, MongoDB returns a list of all database on which you have thefindoperation permissions. Prior to MongoDB 4.0, If you run the command without thelistDatabasesoperation permissions, MongoDB returnsUnauthorized.The default value of
taskExecutorPoolSizeis changed from0to1. On Linux, to restore the previous behavior of a V4.0 deployment, settaskExecutorPoolSizeto0andAsyncRequestsSenderUseBatontofalse.MongoDB 4.0 does not allow you to set
transportLayerandnet.transportLayertolegacyfor mongod and mongos instances.transportLayeris set toasioby default and cannot be changed.Starting from MongoDB 4.0, the
reIndexcommand and itsdb.collection.reIndex()take a global exclusive lock and block other operations until completion.If the values of fields other than
year,isoYear, andtimezoneexceed their valid ranges,$dateFromPartssubtracts 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
killCursorsoperation is changed. Prior to MongoDB 4.0, if obtaining a cursor ID, you can kill any cursor. Starting from MongoDB 4.0,killCursorsallows you to kill any existing cursor. If you do not have permissions to kill a cursor,killCursorsreturns an error.MongoDB 4.0 adds a
killAnyCursoroperation 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 remains4.0, the mongos instance can normally connect to another instance.Starting from MongoDB 4.0, MongoDB resolves
localhostIP addresses based on specified settings, rather than assuming127.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: nonein the configuration file, or use the command line parameter--sslDisabledProtocols none.For mongos instances, use
net.ssl.disabledProtocols: noneor--sslDisabledProtocols none.For the mongo shell, add the
--sslDisabledProtocols noneparameter.The
--sslDisabledProtocolsparameter 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
listCollectionpermission to execute the command.If users without permissions run the command, MongoDB include approximate results in the
authenticatedUserPrivilegesfield returned byconnectionStatus.
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:
Use
mongodumpto dump thetestdatabase to an archived file namedmongodump-test-db.mongodump --archive="mongodump-test-db" --db=testUse
mongorestorealong with the--nsFromand--nsToparameters to restore data from the archived file.mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'
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:
$geoNearaggregation stage$nearquery operator$nearSpherequery 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
replSetGetStatusreturn result are deprecated:replSetGetStatus.syncingToreplSetGetStatus.members[n].syncingTo
Use
replSetGetStatus.replSetGetStatus.syncSourceHostandreplSetGetStatus.members[n].syncSourceHostinstead.The
$currentOpaggregation stage,currentOpcommand, anddb.currentOp()helper function no longer return thethreadIdfield in their output.The
asserts.warningfield ofserverStatusalways returns0.