Release Notes for MongoDB 2.4

MongoDB 2.4 was released on March 19, 2013.

Platform Support

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.

Upgrade Process

See Upgrade MongoDB to 2.4 for full upgrade instructions.

Changes

Major Features

New Geospatial Indexes with GeoJSON and Improved Spherical Geometry

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:

  • Point
  • LineString
  • Polygon

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:

New Hashed Index and Sharding with a Hashed Shard Key

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.

Security Improvements

New Modular Authentication System with Support for Kerberos

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:

Role Based Access Control and New Privilege Documents

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.

Enhanced SSL Support

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.

Compatibility Change: User Uniqueness Enforced

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.

Administration Changes

--setParameter Option Available on the mongos and mongod Command Line

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.

Changes to serverStatus Output Including Additional Metrics

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.

Increased Chunk Migration Write Concern

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.

BSON Document Validation Enabled by Default for mongod and mongorestore

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.

Indexing Changes

Support for Multiple Concurrent Index Builds

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.

db.killOp() Can Now Kill Foreground Index Builds

The db.killOp() method will now terminate a foreground index build, in addition to the other operations supported in previous versions.

Improved Validation of Index Types

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.

Interface Changes

$setOnInsert – New Update Operator

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.

Limit Number of Elements in an Array

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.

See also

The following pages provide additional information and examples:

JavaScript Engine Changed to V8

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:

  • improved concurrency for JavaScript operations,
  • modernized JavaScript implementation, and
  • removed non-standard SpiderMonkey features.

See JavaScript Changes in MongoDB 2.4 for more information about all changes .

Additional Limitations for Map-Reduce and $where Operations

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()

Improvements to the Aggregation Framework

MongoDB 2.4 introduces a number of additional functionality and improved performance for the Aggregation Framework. Consider the following additions in 2.4:

  • $match queries now support the $geoWithin operator for bounded geospatial queries.
  • The new $geoNear pipeline stage to support geospatial queries.
  • $min operator only considers non-null and existing field values. If all the values for a field are null or are missing, the operator returns null for the minimum value.
  • For sort operations where the $sort stage immediately precedes a $limit in the pipeline, the MongoDB can perform a more efficient sort that does not require keeping the entire result set in memory.
  • The new $millisecond operator returns the millisecond portion of a date.
  • The new $concat operator concatenates array of strings.