What Is New in MongoDB 6.2
MongoDB 6.2 is a rapid release packed with enhancements that improve developer productivity, query performance, and operational flexibility. It introduces new aggregation operators, expands time series capabilities, and refines the sharding experience.
| Category | Key Changes |
|---|---|
| New Features | New aggregation operators ($dateAdd, $dateSubtract, $getField, etc.), Compound Hashed Sharding, Hedged Reads |
| Time Series | Delete and compact commands, columnar compression |
| Queryability | Wildcard support on $group _id, $first/$last array operators |
| Security & Operations | Audit log filtering, cluster-wide initial sync, resumable index builds on standalone |
How does MongoDB 6.2 improve aggregation pipelines?
The aggregation framework gets a significant boost with new operators that simplify complex date manipulations and document traversals. The $dateAdd and $dateSubtract operators provide a more intuitive way to perform date arithmetic compared to the older $add and $subtract methods.
For data restructuring, $getField, $setField, and $unsetField allow you to dynamically access and modify fields using string expressions. This is huge for processing documents with variable schemas. You can also use wildcard projections like "$price.*" within a $group's _id field for more flexible grouping logic.
// New date arithmetic
{
$project: {
newDate: {
$dateAdd: {
startDate: "$orderDate",
unit: "day",
amount: 7
}
}
}
}
What new sharding options are available?
Compound Hashed Sharding lets you create a shard key that combines a ranged field with a hashed field. This gives you better distribution for write-heavy workloads while still allowing some range-based query efficiency. It's a solid middle ground between pure hashed and pure ranged sharding.
Hedged Reads are now generally available, letting mongos instances send read operations to multiple replicas and return the first response. This drastically reduces tail latency for queries in globally distributed clusters, especially when some replicas might be experiencing network issues.
How are time series collections enhanced?
You can now run delete operations on time series collections, which was a major limitation before. The new compact command helps reclaim disk space after large deletions, making time series data much more manageable for evolving use cases.
Columnar compression gets support for zstd compression, offering better compression ratios for your time series data. This means lower storage costs and better I/O performance for large-scale time series workloads.
// Deleting data from a time series collection
db.weather.deleteMany({
"metadata.sensorId": 107,
"timestamp": { $lt: ISODate("2022-01-01") }
})
What operational improvements should I know about?
Cluster-wide initial sync allows a new node to sync from any eligible member of the replica set, not just the primary. This reduces load on the primary during scaling operations and makes replica set recovery more flexible.
Standalone servers now support resumable index builds. If you're building a large index and the server restarts, it'll pick up where it left off instead of starting from scratch. For operators, you can now filter audit log output by users or roles, making security reviews more focused.
FAQ
Can I use the new aggregation operators like $dateAdd in older MongoDB versions?
No, these operators are specific to MongoDB 6.2. If you try to use them against an older server version, the aggregation pipeline will fail with an unrecognized operator error.
Does Compound Hashed Sharding replace existing sharding strategies?
It doesn't replace them"it adds a new option. You can still use hashed, ranged, or zoned sharding depending on your use case. Compound Hashed is particularly useful when you need both distribution and some range query efficiency.
What happens if I delete data from a time series collection?
The delete operation marks the underlying data for removal, but the physical disk space isn't immediately reclaimed. You need to run the compact command afterward to actually free up the space, similar to how it works with regular collections.
Are Hedged Reads enabled by default?
No, you need to enable them explicitly by setting the readPreference to "hedged" in your connection string or driver configuration. They're designed for scenarios where low latency is more critical than absolute consistency.
Can I use wildcard projections in $group with nested fields?
Yes, the new wildcard support in $group _id fields works with nested document structures. For example, you can use "metadata.*" to group by all fields within a metadata subdocument.