Release Notes for MongoDB 2.0

Upgrading

Although the major version number has changed, MongoDB 2.0 is astandard, incremental production release and works as a drop-inreplacement for MongoDB 1.8.

Preparation

Read through all release notes before upgrading, and ensure that nochanges will affect your deployment.

If you create new indexes in 2.0, then downgrading to 1.8 is possiblebut you must reindex the new collections.

mongoimport and mongoexport now correctly adhere to the CSV specfor handling CSV input/output. This may break existing import/exportworkflows that relied on the previous behavior. For more information seeSERVER-1097.

Journaling is enabled by default in 2.0 for 64-bit builds.If you still prefer to run without journaling, start mongodwith the —nojournal run-time option.Otherwise, MongoDB creates journal files during startup. The first time you start mongod withjournaling, you will see a delay as mongod creates new files.In addition, you may see reduced write throughput.

2.0 mongod instances are interoperable with 1.8mongod instances; however, for best results, upgrade yourdeployments using the following procedures:

Upgrading a Standalone mongod

  • Download the v2.0.x binaries from the MongoDB Download Page.
  • Shutdown your mongod instance. Replace the existingbinary with the 2.0.x mongod binary and restart MongoDB.

Upgrading a Replica Set

  • Upgrade the secondary members of the set one at a time byshutting down the mongod and replacing the 1.8 binarywith the 2.0.x binary from the MongoDB Download Page.

  • To avoid losing the last few updates on failover you cantemporarily halt your application (failover should take less than 10seconds), or you can set write concern in your applicationcode to confirm that each update reaches multiple servers.

  • Use the rs.stepDown() to step down the primary to allowthe normal failover procedure.

rs.stepDown() and replSetStepDown provide forshorter and more consistent failover procedures than simplyshutting down the primary directly.

When the primary has stepped down, shut down its instance andupgrade by replacing the mongod binary with the 2.0.xbinary.

Upgrading a Sharded Cluster

  • Upgrade all config server instancesfirst, in any order. Since config servers use two-phase commit,shard configuration metadata updates will halt until all areup and running.
  • Upgrade mongos routers in any order.

Changes

Compact Command

A compact command is now available for compacting a singlecollection and its indexes. Previously, the only way to compact was torepair the entire database.

Concurrency Improvements

When going to disk, the server will yield the write lock when writingdata that is not likely to be in memory. The initialimplementation of this feature now exists:

See SERVER-2563 for more information.

The specific operations yield in 2.0 are:

  • Updates by _id
  • Removes
  • Long cursor iterations

Default Stack Size

MongoDB 2.0 reduces the default stack size. This change can reduce total memoryusage when there are many (e.g., 1000+) client connections, as there isa thread per connection. While portions of a thread’s stack can beswapped out if unused, some operating systems do this slowly enough thatit might be an issue. The default stack size is lesser of thesystem setting or 1MB.

Index Performance Enhancements

v2.0 includes significant improvements to theindex.Indexes are often 25% smaller and 25% faster (depends on the use case).When upgrading from previous versions, the benefits of the new indextype are realized only if you create a new index or re-index an old one.

Dates are now signed, and the max index key size has increased slightlyfrom 819 to 1024 bytes.

All operations that create a new index will result in a 2.0 index bydefault. For example:

  • Reindexing results on an older-version index results in a 2.0 index.However, reindexing on a secondary does not work in versions priorto 2.0. Do not reindex on a secondary. For a workaround, seeSERVER-3866.
  • The repairDatabase command converts indexes to a 2.0indexes.

To convert all indexes for a given collection to the 2.0 type, invoke the compact command.

Once you create new indexes, downgrading to 1.8.x will require are-index of any indexes created using 2.0. See/tutorial/roll-back-to-v1.8-index.

Sharding Authentication

Applications can now use authentication with sharded clusters.

Replica Sets

Hidden Nodes in Sharded Clusters

In 2.0, mongos instances can now determine when a member ofa replica set becomes “hidden” without requiring a restart. In 1.8,mongos if you reconfigured amember as hidden, you had to restart mongos to preventqueries from reaching the hidden member.

Priorities

Each replica set member can now have a priority value consistingof a floating-point from 0 to 1000, inclusive. Priorities let youcontrol which member of the set you prefer to have as primarythe member with the highest priority that can see a majority of the setwill be elected primary.

For example, suppose you have a replica set with three members, A, B, andC, and suppose that their priorities are set as follows:

  • A’s priority is 2.
  • B’s priority is 3.
  • C’s priority is 1.

During normal operation, the set will always chose B asprimary. If B becomes unavailable, the set will elect A as primary.

For more information, see thepriority documentation.

Data-Center Awareness

You can now “tag” replica set members to indicate theirlocation. You can use these tags to design custom write rulesacross data centers, racks, specific servers, or any other architecturechoice.

For example, an administrator can define rules such as “very important write” orcustomerData or “audit-trail” to replicate to certain servers,racks, data centers, etc. Then in the application code, the developerwould say:

  1. db.foo.insert(doc, {w : "very important write"})

which would succeed if it fulfilled the conditions the DBA defined for“very important write”.

For more information, see Data Center Awareness.

Drivers may also support tag-aware reads. Instead ofspecifying slaveOk, you specify slaveOk with tags indicatingwhich data-centers to read from. For details, see theDrivers documentation.

w : majority

You can also set w to majority to ensure that the writepropagates to a majority of nodes, effectively committing it. Thevalue for “majority” will automatically adjust as you add orremove nodes from the set.

For more information, see Write Concern.

Reconfiguration with a Minority Up

If the majority of servers in a set has been permanently lost, you cannow force a reconfiguration of the set to bring it back online.

For more information see Reconfigure a Replica Set with Unavailable Members.

Primary Checks for a Caught up Secondary before Stepping Down

To minimize time without a primary, the rs.stepDown()method will now fail if the primary does not see a secondarywithin 10 seconds of its latest optime. You can force the primary tostep down anyway, but by default it will return an error message.

See also Force a Member to Become Primary.

Extended Shutdown on the Primary to Minimize Interruption

When you call the shutdown command, the primarywill refuse to shut down unless there is a secondary whoseoptime is within 10 seconds of the primary. If such a secondary isn’tavailable, the primary will step down and wait up to a minute for thesecondary to be fully caught up before shutting down.

Note that to get this behavior, you must issue the shutdowncommand explicitly; sending a signal to the process will not triggerthis behavior.

You can also force the primary to shut down, even without an up-to-datesecondary available.

Maintenance Mode

When repairDatabase or compact runs on a secondary, thesecondary will automatically drop into “recovering” mode until theoperation finishes. This prevents clients from trying to read from itwhile it’s busy.

Geospatial Features

Multi-Location Documents

Indexing is now supported on documents which have multiple locationobjects, embedded either inline or in embedded documents. Additionalcommand options are also supported, allowing results to return withnot only distance but the location used to generate the distance.

For more information, see Multi-location Documents for 2d Indexes.

Polygon searches

Polygonal $within queries are also now supported for simple polygonshapes. For details, see the $within operator documentation.

Journaling Enhancements

  • Journaling is now enabled by default for 64-bit platforms. Use the—nojournal command line option to disable it.
  • The journal is now compressed for faster commits to disk.
  • A new —journalCommitInterval run-time option exists forspecifying your own group commit interval. The default settings donot change.
  • A new { getLastError: { j: true } } option isavailable to wait for the group commit. The group commit will happensooner when a client is waiting on {j: true}. If journaling isdisabled, {j: true} is a no-op.

New ContinueOnError Option for Bulk Insert

Set the continueOnError option for bulk inserts, in thedriver, so that bulk insert willcontinue to insert any remaining documents even if an insert fails, asis the case with duplicate key exceptions or network interruptions. The getLastErrorcommand will report whether any inserts have failed, not just thelast one. If multiple errors occur, the client will only receive themost recent getLastError results.

Note

For bulk inserts on sharded clusters, the getLastErrorcommand alone is insufficient to verify success. Applicationsshould must verify the success of bulk inserts in applicationlogic.

Map Reduce

Output to a Sharded Collection

Using the new sharded flag, it is possible to send the result of amap/reduce to a sharded collection. Combined with the reduce ormerge flags, it is possible to keep adding data to very largecollections from map/reduce jobs.

For more information, see Map-Reduce and themapReduce reference.

Performance Improvements

Map/reduce performance will benefit from the following:

  • Larger in-memory buffer sizes, reducing the amount of disk I/O neededduring a job
  • Larger javascript heap size, allowing for larger objectsand less GC
  • Supports pure JavaScript execution with the jsMode flag. See themapReduce reference.

New Querying Features

Additional regex options: s

Allows the dot (.) to match all characters including new lines. This isin addition to the currently supported i, m and x. See $regex.

$and

A special boolean $and query operator is now available.

Command Output Changes

The output of the validate command and the documents in thesystem.profile collection have both been enhanced to returninformation as BSON objects with keys for each value rather than asfree-form strings.

Shell Features

Custom Prompt

You can define a custom prompt for the mongo shell. You canchange the prompt at any time by setting the prompt variable to a stringor a custom JavaScript function returning a string. For examples, seeCustomize the Prompt.

Default Shell Init Script

On startup, the shell will check for a .mongorc.js file in theuser’s home directory. The shell will execute this file after connectingto the database and before displaying the prompt.

If you would like the shell not to run the .mongorc.js fileautomatically, start the shell with —norc.

For more information, see the mongo reference.

Most Commands Require Authentication

In 2.0, when running with authentication (e.g. authorization) all_database commands require authentication, _except the followingcommands.

Resources