When going to disk, the server will yield the write lock when writing data that is not likely to be in memory. The initial implementation of this feature now exists:
See SERVER-2563 for more information.
The specific operations yield in 2.0 are:
- Updates by
- Long cursor iterations
Default Stack Size
MongoDB 2.0 reduces the default stack size. This change can reduce total memory usage when there are many (e.g., 1000+) client connections, as there is a thread per connection. While portions of a thread’s stack can be swapped out if unused, some operating systems do this slowly enough that it might be an issue. The default stack size is lesser of the system setting or 1MB.
Index Performance Enhancements
v2.0 includes significant improvements to the index . Indexes are often 25% smaller and 25% faster (depends on the use case). When upgrading from previous versions, the benefits of the new index type 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 slightly from 819 to 1024 bytes.
All operations that create a new index will result in a 2.0 index by default. 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 prior to 2.0. Do not reindex on a secondary. For a workaround, see SERVER-3866 .
repairDatabase command converts indexes to a 2.0 indexes.
To convert all indexes for a given collection to the 2.0 type, invoke the
Once you create new indexes, downgrading to 1.8.x will require a re-index of any indexes created using 2.0. See /tutorial/roll-back-to-v1.8-index .
Each replica set member can now have a priority value consisting of a floating-point from 0 to 1000, inclusive. Priorities let you control which member of the set you prefer to have as primary the member with the highest priority that can see a majority of the set will be elected primary.
For example, suppose you have a replica set with three members,
C, and suppose that their priorities are set as follows:
A’s priority is
B’s priority is
C’s priority is
During normal operation, the set will always chose
B as primary. If
B becomes unavailable, the set will elect
A as primary.
For more information, see the
You can now “tag” replica set members to indicate their location. You can use these tags to design custom write rules across data centers, racks, specific servers, or any other architecture choice.
For example, an administrator can define rules such as “very important write” or
customerData or “audit-trail” to replicate to certain servers, racks, data centers, etc. Then in the application code, the developer would say:
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 of specifying
slaveOk, you specify
slaveOk with tags indicating which data-centers to read from. For details, see the Drivers documentation.
You can also set
majority to ensure that the write propagates to a majority of nodes, effectively committing it. The value for “majority” will automatically adjust as you add or remove nodes from the set.
For more information, see Write Concern.
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 secondary within 10 seconds of its latest optime. You can force the primary to step 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 primary will refuse to shut down unless there is a secondary whose optime is within 10 seconds of the primary. If such a secondary isn’t available, the primary will step down and wait up to a minute for the secondary to be fully caught up before shutting down.
Note that to get this behavior, you must issue the
shutdown command explicitly; sending a signal to the process will not trigger this behavior.
You can also force the primary to shut down, even without an up-to-date secondary available.
compact runs on a secondary, the secondary will automatically drop into “recovering” mode until the operation finishes. This prevents clients from trying to read from it while it’s busy.
Indexing is now supported on documents which have multiple location objects, embedded either inline or in embedded documents. Additional command options are also supported, allowing results to return with not only distance but the location used to generate the distance.
For more information, see Multi-location Documents for 2d Indexes.
$within queries are also now supported for simple polygon shapes. For details, see the
$within operator documentation.