What Is New in MongoDB 1.8
MongoDB 1.8 introduces significant enhancements focused on durability, performance, and new operational commands. This release marks a major step forward in production readiness.
| Category | Key Changes |
|---|---|
| Durability | Journaling, Single Server Durability |
| Replication | Replica Set Authentication, --shardsvr mode |
| Commands | compact, touch, $or optimization |
| Concurrency | Improved locking granularity |
| Deprecations | Master-Slave replication, --notablescan |
How does journaling improve MongoDB durability?
Journaling is the flagship feature for MongoDB 1.8, providing single-server durability. It prevents data corruption in the event of an unclean shutdown, like a power failure.
The journal is a write-ahead log where changes are recorded before being applied to the main data files. This means if the server crashes, MongoDB can replay the journal to recover all writes that were committed. In practice, this eliminates the need for a replication setup just to achieve basic data safety on a single node.
What replication enhancements were added?
Replica sets gained internal authentication support, allowing members to use a shared keyfile to authenticate with each other. This secures communication within the replica set, preventing unauthorized nodes from joining.
The --shardsvr option was also introduced. This mode is crucial for sharded clusters as it configures a mongod instance to expect routing and coordination from mongos processes, paving the way for more advanced deployments.
Which new commands help with database operations?
The compact command defragments data files and releases unused space back to the operating system. This is a significant improvement over the previous method of using repairDatabase, which required double the disk space and took much longer.
The touch command was added to load data or indexes into memory without forcing a table scan. This is useful for pre-warming the cache before putting a database under load, ensuring predictable performance from the start.
How was concurrency and performance improved?
Locking granularity saw major improvements. MongoDB 1.8 implemented more granular locks in certain operations, reducing contention and allowing for better concurrent read and write performance.
Query performance got a boost with optimizations for $or queries. The optimizer became smarter about how it executes these queries, often leading to faster results. This matters because $or is a common operator used in application logic.
What features were deprecated in this release?
Master-Slave replication was officially deprecated in favor of replica sets. Replica sets offer automatic failover and better robustness, making the older master-slave mode obsolete.
The --notablescan option was also deprecated. While it was intended to prevent slow full collection scans, the community found it too restrictive for general use. The preferred method became using the profiler to identify and optimize slow queries instead.
FAQ
Should I always enable journaling on a standalone server?
Yes, absolutely. The minimal performance overhead is far outweighed by the guarantee that your data will survive a crash. It's a default setting for a reason and is considered essential for any production deployment.
Can I mix replica sets with master-slave in 1.8?
Technically yes, but it's not recommended. Master-slave is deprecated, and replica sets are the superior architecture. You should migrate any existing master-slave setups to replica sets for better automation and reliability.
What's the real-world impact of the improved $or optimization?
Applications that heavily use $or clauses in their queries will see the most benefit. The optimizer can now use indexes more effectively for each branch of the $or, turning what was often a slow table scan into a series of fast index scans.
Why was --notablescan deprecated instead of improved?
It was a blunt instrument. In practice, it could break legitimate queries and applications. The MongoDB team shifted focus to providing better tools, like the database profiler, to help developers find and fix slow queries themselves.
Is the compact command safe to run on a live production database?
It blocks operations on the database it is running on, so it will cause downtime. You should schedule it during a maintenance window. The benefit is that it no longer requires 100% free disk space like repairDatabase did.