See the full index of this page for a complete list of changes included in 2.4.
MongoDB 2.4 was released on March 19, 2013.
For OS X, MongoDB 2.4 only supports OS X versions 10.6 (Snow Leopard) and later. There are no other platform support changes in MongoDB 2.4. See the downloads page for more information on platform support.
MongoDB 2.4 adds text search of content in MongoDB databases as a beta feature. With the new text index, and supporting, text command you can search for text using boolean queries in data stored in MongoDB, using an index that updates in real-time and is always consistent with the data set. See Text Search for more information about text search in MongoDB.
MongoDB adds the new 2dsphere geospatial index in addition to the existing 2d index. The 2dsphere index supports improved spherical queries and supports the following GeoJSON objects:
The 2dsphere index supports all current geospatial query operators and introduces the following new query operator for queries on GeoJSON data:
The operators use the new $geometry parameter.
The $within operator no longer requires a geospatial index. Additionally, 2.4 deprecates the $within operator. Use $geoWithin operator instead.
For more information on geospatial indexes in 2.4, see:
To support an easy to configure and evenly distributed shard key, version 2.4 adds a new “hashed” index type that indexes documents using hashes of field values.
See Hashed Index for documentation of hashed indexes, and Hashed Sharding for documentation of hash-based sharding.
Note
Kerberos authentication is only present in MongoDB Enterprise Edition. To download and install MongoDB Enterprise, see Install MongoDB Enterprise.
In 2.4 the MongoDB Enterprise now supports authentication via a Kerberos mechanism. See Deploy MongoDB with Kerberos Authentication for more information.
Also consider the following documents that address authenticating to MongoDB using Kerberos:
MongoDB 2.4 introduces a role based access control system that provides more granular privileges to MongoDB users. See User Privilege Roles in MongoDB for more information.
To support the new access control system, 2.4 also introduces a new format for documents in a database’s system.users collection. See system.users Privilege Documents for more information.
Use supportCompatibilityFormPrivilegeDocuments to disable the legacy privilege documents, which MongoDB continues to support in 2.4.
In 2.4, MongoDB instances can optionally require clients to provide SSL certificates signed by a Certificate Authority. You must use the MongoDB distribution that supports SSL, and your client driver must support SSL. See Connect to MongoDB with SSL for more information.
2.4 now enforces uniqueness of the user field in user privilege documents (i.e. in the system.users collection.) Previous versions of MongoDB did not enforce this requirement, and existing databases may have duplicates.
You can now use --setParameter on the command line and setParameter in the configuration file. For mongod the following options are available using setParameter:
For mongos the following options are available using setParameter:
See mongod Parameters for full documentation of available parameters and their use.
In 2.4 MongoDB adds a number of counters and system metrics to the output of the serverStatus command, including:
Additionally, in 2.4, the serverStatus command can dynamically construct the serverStatus document by excluding any top-level sections included by default, or including any top-level section not included by default (e.g. workingSet.)
See db.serverStatus() and serverStatus for more information.
By default, all insert and delete operations that occur as part of a chunk migration in a sharded cluster will have an increased write concern, to ensure that at least one secondary acknowledges each insert and deletion operation. This change slows the potential speed of a chunk migration, but increases reliability and ensures that a large number of chunk migrations cannot affect the availability of a sharded cluster.
Starting in 2.4, MongoDB enables basic BSON object validation for mongod and mongorestore when writing to MongoDB data files. This prevents any client from inserting invalid or malformed BSON into a MongoDB database. For objects with a high degree of sub-document nesting this validation may have a small performance impact. objcheck, which was previously disabled by default, provides this validation.
A single mongod instance can build multiple indexes in the background at the same time. See building indexes in the background for more information on background index builds. Foreground index builds hold a database lock and must proceed one at a time.
The db.killOp() method will now terminate a foreground index build, in addition to the other operations supported in previous versions.
Before 2.4, mongod would create an ascending scalar index (e.g. { a : 1 }) when users attempted to create an index of a type that did not exist. Creating an index of an invalid index type will generate an error in 2.4.
See Compatibility and Index Type Changes in MongoDB 2.4 for more information.
To set fields only when an upsert performs an insert, use the $setOnInsert operator with the upsert .
Example
A collection named coll has no documents with _id equal to 1.
The following upsert operation inserts a document and applies the $setOnInsert operator to set the fields x and y:
db.coll.update( { _id: 1 },
{ $setOnInsert: { x: 25, y: 30 } },
{ upsert: true } )
The newly-inserted document has the field x set to 25 and the field y set to 30:
{ "_id" : 1, "x" : 25, "y" : 30 }
Note
The $setOnInsert operator performs no operation for upserts that only perform an update and for updates when the upsert option is false.
In 2.4, by using the $push operator with the $each, the $sort, and the $slice modifiers, you can add multiple elements to an array, sort and limit the number of elements in the modified array to maintain an array with a fixed number of elements.
See Limit Number of Elements in an Array after an Update for an example where an update maintains the top three scores for a student.
In 2.4 the default JavaScript engine in the mongo shell mongod is now V8. This change affects all JavaScript behavior including the mapReduce, group, and eval commands, as well as the $where query operator.
Use the new interpreterVersion() method in the mongo shell and the javascriptEngine field in the output of db.serverBuildInfo() to determine which JavaScript engine a MongoDB binary uses.
The primary impacts of the change from the previous JavaScript engine, SpiderMonkey, to V8 are:
See JavaScript Changes in MongoDB 2.4 for more information about all changes .
In MongoDB 2.4, map-reduce operations, the group command, and $where operator expressions cannot access certain global functions or properties, such as db, that are available in the mongo shell.
When upgrading to MongoDB 2.4, you will need to refactor your code if your map-reduce operations, group commands, or $where operator expressions include any global shell functions or properties that are no longer available, such as db.
The following shell functions and properties are available to map-reduce operations, the group command, and $where operator expressions in MongoDB 2.4:
| Available Properties | Available Functions | |
|---|---|---|
args
MaxKey
MinKey
|
assert()
BinData()
DBPointer()
DBRef()
doassert()
emit()
gc()
HexData()
hex_md5()
isNumber()
isObject()
ISODate()
isString()
|
Map()
MD5()
NumberInt()
NumberLong()
ObjectId()
print()
printjson()
printjsononeline()
sleep()
Timestamp()
tojson()
tojsononeline()
tojsonObject()
UUID()
version()
|
MongoDB 2.4 introduces a number of additional functionality and improved performance for the Aggregation Framework. Consider the following additions in 2.4: