Premium Hosted Website & Server Monitoring Tool.

(Sysadmin / Devops blog)

visit our website

Blog   >   MongoDB   >   Interesting changes in MongoDB 2.2 you might not know about

Interesting changes in MongoDB 2.2 you might not know about

MongoDB

MongoDB 2.2 RC1 was released yesterday and includes a few major features you’re probably already aware of: a new aggregation framework, removal of the global lock and tag aware sharding. However, there are quite a few other improvements and changes which are worth learning about. This post will introduce you to a few of them. Everything else you can find out about from the official MongoDB 2.2 release notes.

Shard keys can be a compound index: Pre 2.2, the shard index could not be part of an existing index. So if you wanted a shard key of {accountId: 1, serverId: 1} but wanted an index to for queries with some extra fields e.g. {accountId: 1, serverId: 1, lastPostback: 1} then you had to create 2 indexes. This causes duplication. In 2.2 so long as the shard key is at the start of the index, it can be the same one. So in the example here, we can remove the first index and just use the second, 3 field index.

mongooplog tool: this allows you to run through the oplog from Server A on Server B without affecting the usage of Server A. This is useful if you want to migrate data from Server A whilst keeping it online. If the source server can be taken offline then it’s probably quicker to use the existing dump/restore tools. See the docs for more details.

Shell Improvements: the shell becomes much more like a bash shell with features like unicode support, multi-line command histories and various shortcuts to make the shell more like EMACS-style editing. A full list of all the shortcuts is included at the end of this post and can also found here.

Log to syslog: Instead of logging to a file, mongod can send all its log output to syslog with the new --syslog parameter. This helps with centralised logging rather than having to parse another log file.

touch command: This allows you to force MongoDB to read the data and/or indexes from a specific collection into memory. This is useful to help with cold start where no data or indexes are in memory when you first launch a MongoDB server and you want to quickly get certain data in memory to avoid disk seeks. Note that a cold start is not simply restarting the mongod process because MongoDB uses the OS memory management so data will remain in memory even across processes. This is more useful when bringing a new server online after a reboot. See the docs for more info.

Force replication resync from a specific member: MongoDB does a good job of selecting the best node to resync data from in a replica set. This is done using flags such as the ping time between nodes and whether nodes are primary or not (preference for copying the data from slaves then the final sync up to date from the master, with the goal of not causing a performance hit on the master). The new replSetSyncFrom command, and rs.syncFrom() shell helper allow you to choose the node yourself.

New sharding migration thresholds Pre 2.2, shard balancing would only happen if there was an imbalance of 8 or more chunks. This is now graded based on the total number of chunks.

MongoDB Migration Thresholds

MongoDB shell keyboard shortcuts:

MongoDB Shell Keyboard Shortcuts (1 of 2)
MongoDB Shell Keyboard Shortcuts (2 of 2)