翻译或纠错本页面

Compatibility Changes in MongoDB 3.2

The following 3.2 changes can affect the compatibility with older versions of MongoDB. See also Release Notes for MongoDB 3.2 for the list of the 3.2 changes.

Default Storage Engine Change

Starting in 3.2, MongoDB uses the WiredTiger as the default storage engine. Previous versions used the MMAPv1 as the default storage engine.

For existing deployments, if you do not specify the --storageEngine or the storage.engine setting, MongoDB automatically determines the storage engine used to create the data files in the --dbpath or storage.dbPath.

For new deployments, to use MMAPv1, you must explicitly specify the storage engine setting either:

  • On the command line with the --storageEngine option:

    mongod --storageEngine mmapv1
    
  • Or in a configuration file, using the storage.engine setting:

    storage:
       engine: mmapv1
    

Index Changes

Version 0 Indexes

MongoDB 3.2 disallows the creation of version 0 indexes (i.e. {v: 0}). If version 0 indexes exist, MongoDB 3.2 outputs a warning log message, specifying the collection and the index.

Starting in MongoDB 2.0, MongoDB started automatically upgrading v: 0 indexes during initial sync, mongorestore or reIndex operations.

If a version 0 index exists, you can use any of the aforementioned operations as well as drop and recreate the index to upgrade to the v: 1 version.

For example, if upon startup, a warning message indicated that an index index { v: 0, key: { x: 1.0 }, name: "x_1", ns: "test.legacyOrders" } is a version 0 index, to upgrade to the appropriate version, you can drop and recreate the index:

  1. Drop the index either by name:

    use test
    db.legacyOrders.dropIndex( "x_1" )
    

    or by key:

    use test
    db.legacyOrders.dropIndex( { x: 1 } )
    
  2. Recreate the index without the version option v:

    db.legacyOrders.createIndex( { x: 1 } )
    

Text Index Version 3 Compatibility

Text index (version 3) is incompatible with earlier versions of MongoDB. Earlier versions of MongoDB will not start if text index (version 3) exists in the database.

2dsphere Index Version 3 Compatibility

2dsphere index (version 3) is incompatible with earlier versions of MongoDB. Earlier versions of MongoDB will not start if 2dsphere index (version 3) exists in the database.

Aggregation Compatibility Changes

  • $avg accumulator returns null when run against a non-existent field. Previous versions returned 0.
  • $substr errors when the result is an invalid UTF-8. Previous versions output the invalid UTF-8 result.
  • Array elements are no longer treated as literals in the aggregation pipeline. Instead, each element of an array is now parsed as an expression. To treat the element as a literal instead of an expression, use the $literal operator to create a literal value.

SpiderMonkey Compatibility Changes

MongoDB 3.2 changes the JavaScript engine from V8 to SpiderMonkey. The change allows the use of more modern JavaScript language features, and comes along with minor mongo shell improvements and compatibility changes.

See JavaScript Changes in MongoDB 3.2 for more information about this change.

Driver Compatibility Changes

A driver upgrade is necessary to support the find and getMore commands.

General Compatibility Changes

Additional Information

See also Release Notes for MongoDB 3.2.