Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Compatibility and Index Type Changes in MongoDB 2.4

On this page

  • New Index Types
  • Index Type Validation

In 2.4 MongoDB includes two new features related to indexes that users upgrading to version 2.4 must consider, particularly with regard to possible downgrade paths. For more information on downgrades, see Downgrade MongoDB from 2.4 to Previous Versions.

In 2.4 MongoDB adds two new index types: 2dsphere and text. These index types do not exist in 2.2, and for each database, creating a 2dsphere or text index, will upgrade the data-file version and make that database incompatible with 2.2.

If you intend to downgrade, you should always drop all 2dsphere and text indexes before moving to 2.2.

You can use the downgrade procedure to downgrade these databases and run 2.2 if needed, however this will run a full database repair (as with repairDatabase) for all affected databases.

In MongoDB 2.2 and earlier you could specify invalid index types that did not exist. In these situations, MongoDB would create an ascending (e.g. 1) index. Invalid indexes include index types specified by strings that do not refer to an existing index type, and all numbers other than 1 and -1. [1]

In 2.4, creating any invalid index will result in an error. Furthermore, you cannot create a 2dsphere or text index on a collection if its containing database has any invalid index types. [1]


If you attempt to add an invalid index in MongoDB 2.4, as in the following:

db.coll.ensureIndex( { field: "1" } )

MongoDB will return the following error document:

"err" : "Unknown index plugin '1' in index { field: \"1\" }"
"code": 16734,
"n": <number>,
"connectionId": <number>,
"ok": 1
[1](1, 2) In 2.4, indexes that specify a type of "1" or "-1" (the strings "1" and "-1") will continue to exist, despite a warning on start-up. However, a secondary in a replica set cannot complete an initial sync from a primary that has a "1" or "-1" index. Avoid all indexes with invalid types.
←  Upgrade MongoDB to 2.4Release Notes for MongoDB 2.2 →