All Products
Search
Document Center

:Compatibility changes in MongoDB 3.4

Last Updated:Apr 16, 2025

This topic describes the compatibility changes in MongoDB 3.4.

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

Changes to sharded cluster instances

Explicit member roles

In a sharded cluster instance that runs MongoDB 3.4, all mongod instances in shards must explicitly declare their role as shardsvr through one of the following methods:

  • Configuration file: Specify sharding.clusterRole: shardsvr.

  • Command line: Use the --shardsvr option.

Note

The default port for mongod instances with the shardsvr role is 27018. To use a different port, set the net.port configuration option or the --port parameter to the port.

Compatibility limits

A mongos instance that runs MongoDB 3.4 cannot connect to a mongod instance that runs an earlier version.

Removal of configuration options

MongoDB 3.4 removes the following configuration options from mongos:

  • Chunk size configuration:

    • Configuration file option sharding.chunkSize.

    • Command line option --chunkSize.

  • Automatic splitting configuration:

    • Configuration file option sharding.autoSplit.

    • Command line option --noAutoSplit.

Deprecation of SCCC configuration servers

Starting from MongoDB 3.4, sharded cluster instances no longer support mirrored (SCCC) mongod instances as configuration servers. This mode is deprecated in MongoDB 3.2.

You must deploy your configuration server in replica set mode (CSRS). To upgrade your sharded cluster instance to MongoDB 3.4, your configuration server must meet the following requirements:

  • It must be running in CSRS mode.

  • If it is in SCCC mode, you can convert it to the CSRS mode.

Compatibility of collection renaming with initial sync

If a collection, as a synchronization source, is renamed during initial sync, the initial sync process fails and is restarted, thereby avoiding potential data corruption risks. For more information, see SERVER-26117.

The following pperations involve collection renaming:

  • The renameCollection command: such as the db.collection.renameCollection() method.

  • The $out stage in an aggregation operation, such as using the db.collection.aggregate() method or the aggregate command with the $out stage.

  • The out option in MapReduce, such as using the db.collection.mapReduce() method or the mapReduce command with the out option specified.

  • The convertToCapped command that is used to convert a regular collection to a capped collection.

When you upgrade from MongoDB 3.2.11 or earlier to 3.4, initial sync may fail if encountering a collection renaming operation.

Priior to MongoDB v3.2.11, an initial sync process continues when encountering a collection renamimng operation that may corrupt data. For more information, see SERVER-4941.

Deprecated operations

group command

Starting from MongoDB 3.4, the group command and the mongo shell method db.collection.group() are deprecated. Use db.collection.aggregate() or db.collection.mapReduce() instead.

aggregate command without cursor information

Starting from MongoDB 3.6, the output of the aggregate command must include a cursor in the cursor option, unless the explain option is specified for analyzing the execution plan.

  • To indicate a cursor with the default batch size, specify cursor: {}.

  • To indicate a cursor with the non-default batch size, use cursor: { batchSize: <num> }.

Collection and index specifications

Collection option validation

Starting from MongoDB 3.4, the create command and a db.createCollection() operation perform a stricter validation of collection options. You must use valid options supported by create or db.createCollection().

For example, the following operation is no longer valid because it includes an invalid option cappedtypo:

db.createCollection( "myCappedCollection", { cappedtypo: true, size: 5242880 } )

Index specification validation

Starting from MongoDB 3.4, the createIndexes command and thedb.collection.createIndex() method perform a stricter validation when you create indexes. This stricter validation does take effect on existing indexes. The following validation rules apply:

  • Make sure that the value In the index key pattern key: value is valid. Allowed values:

    Value

    Description

    Number > 0

    For ascending indexes.

    Number < 0

    For descending indexes.

    String

    For special index types, only "text", "2dsphere", "2d", and "hashed" are allowed.

    For example, the following operations are no longer valid:

    db.collection.createIndex( { x: 0 } );
    db.collection.createIndex( { y: "text2d" } );
    db.collection.createIndex( { z: NaN } );
    db.collection.createIndex( { x: 1, unique: true } )
  • Make sure that specified index ptions are valid. Prior to MongoDB 3.4, invalid index options are ignored. However, starting from MongoDB 3.4, MongoDB reports an error if you specify invalid index options. For example, the following operations are no longer valid:

    db.collection.createIndex( { y: 1 }, { uniques2: true} );
    db.collection.createIndex( { z: 1 }, { expireAfterSec: 350 } )

General compatibility changes

  • Adjustment of namespace limits: Starting from MongoDB 3.4, database names no longer support the $ symbol.

    Note

    Before upgrading to MongoDB 3.4, you must delete all databases whose names contain $.

  • Removal of the textSearchEnabled parameter. Starting from MongoDB 2.6, MongoDB enables text search by default.

  • Removal of the mongosniff tool: Starting from MongoDB 3.4, mongosniff is replaced by the tool mongoreplay that provides more powerful features and supports more flexible network traffic capture and analysis.

  • Changes to the $project aggregation stage behavior: If the $project stage returns an empty document (no fields preserved or added), an error is reported.

  • Counting issues of hints and sparse indexes: If you use a hint() that specifies a sparse index when counting documents in a collection (with an empty query predicate), the sparse index may cause inaccurate counting results.

    db.collection.insert({ _id: 1, y: 1 } );
    db.collection.createIndex( { x: 1 }, { sparse: true } );
    
    db.collection.find().hint( { x: 1 } ).count();

    To obtain the correct counting results, do not specify a sparse index in a hint() when counting all documents in a collection.

    db.collection.find().count();
    
    db.collection.createIndex({ y: 1 });
    db.collection.find().hint({ y: 1 }).count();

    Prior to MongoDB 3.4, hints are ignored if the use of sparse indexes cause the missing count results.

Changes to user role permissions

Starting from MongoDB 3.4, the permissions of the following built-in roles no longer apply to the local and config databases:

Role name

Description

readAnyDatabase

To grant read permissions on the local database, create a user in the admin database and explicitly assign the read role of the local database to the user. Alternatively, access the config and local databases with the clusterManager or clusterMonitor role.

readWriteAnyDatabase

To grant read/write permissions on the local database, create a user in the admin database and explicitly assign the readWrite role of the local database to the user.

userAdminAnyDatabase

N/A.

dbAdminAnyDatabase

To grant administrative permissions on the local database, create a user in the admin database and explicitly assign the dbAdmin role of the local database to the user.

The following built-in roles have permissions on the local and config databases:

  • clusterManager

  • clusterMonitor

  • backup

  • restore

Features incompatible with later versions

MongoDB 3.4 introduces the following features that persist data improperly processed by earlier versions. To enable these features, set featureCompatibilityVersion to "3.4".

  • Views

  • Collation and case-insensitive indexes

  • Decimal type

  • Index version v2

    • Supports collation and decimal data types.

    • When featureCompatibilityVersion is set to "3.4", the default version of new indexes is v2. Otherwise, the default version is v1.

Note

Once enabled, these incompatible features complicate the download process.

To minimize the downgrade possibility, we recommend that you allow your deployment to run without enabling these features after upgrad. Enable these features only when you ensure that the downgrade possibility is minimal.

Default featureCompatibilityVersion values:

  • Fresh deployments of MongoDB 3.4: "3.4".

  • Deployments upgraded from MongoDB 3.2: "3.2" (needs to be manually set to "3.4").

Prior to MongoDB 3.4, if a database contains views, collation definitions, or v2 indexes, MongoDB cannot start. If decimal type fields exist, operations for these documents may fail.

For upgrade to MongoDB 3.4, you must clear all incompatible data, including views, v2 indexes, and decimal fields.

Driver compatibility changes

To use the new features introduced in MongoDB 3.4 (such as decimal type and collation), you must upgrade your driver to a version that supports these features.

Single-element $in and upsert behavior changes

When an upsert operation finds no matching documents, it creates a base document for upserts based on the equality statement in a query predicate, and then applies update operators to the document. Example:

db.c.drop()
db.c.update( { a : 3, b: "foo" }, { $set : { c : 15 } }, { upsert : true } )
db.c.find()
{ "_id" : ObjectId("59c03009529946822d0afb8c"), "a" : 3, "b" : "foo", "c" : 15 }

Prior to MongoDB 3.4, a single-element $in does not initialize fields.

db.c.drop()
db.c.update( { a : { $in : [1] } }, { $addToSet : { a : 2 } }, { upsert : true } )
db.c.find()
{ "_id" : ObjectId("58bdb00eb39e8f87607e9222"), "a" : [ 2 ] }

Starting from MongoDB 3.4, a single-element $in is treated as an equality statement for upserts:

  • If a query predicate includes a single-element $in, the fields are initialized as scalar fields rather than arraies.

  • The $addToSet operation in the preceding example fails because array operators cannot be applied to the scalar fields.

Solution: Wrap the $in expression in $elemMatch to forcibly maintain the array type of the fields.

db.c.drop()
db.c.update(
   { a : { $elemMatch : { $in : [ 2 ] } } },
   { $addToSet : { a: 3 } },
   { upsert: true } )
db.c.find()
{ "_id" : ObjectId("..."), "a" : [ 3 ] }