Improved Performance in Aggregations
The newly implemented slot-based query execution engine improves performance for a wider range of find and aggregation queries. MongoDB can use the slot-based query execution engine for a subset of queries provided certain conditions are met. In most cases, the slot-based execution engine provides improved performance and lower CPU and memory costs compared to the classic query engine.
Compound Wildcard Indexes
You can now create compound wildcard indexes. A compound wildcard index has one wildcard term and one or more additional index terms. Use compound wildcard indexes to support queries on known patterns and to limit the total number of indexes in a collection.
Consider a collection like this:
{
tenantId: <Number>,
tenantRegion: <Number>,
customFields: {
addr: <String>,
name: <String>,
blockId: <Number>,
...
}
dateOpened: <Date>
}
If we have query patterns where we always need to query by the tenantId but also any of the fields in customFields, this will lead to an index for every combination, but now we can create a compounded wildcard index that will cover any combination.
db.runCommand(
{
createIndexes: "salesData",
indexes: [
{
key: {
tenantId: 1,
"customFields.$**": 1
},
name: "tenant_customFields"
}
]
}
)
Large Change Stream Events
If you have change stream events larger than 16 MB, you can use the new $changeStreamSplitLargeEvent stage to split the events into smaller fragments.
The following new metrics report information about large change stream events:
- metrics.changeStreams
- metrics.changeStreams.largeEventsFailed
- metrics.changeStreams.largeEventsSplit
New Aggregation Operators
$median
Returns an approximation of the median, the 50th percentile, as a scalar value. It can be used in the $group or $setWindowFields stage or as an aggregation expression in $project
{
$median: {
input: <number>,
method: <string>
}
}
$percentile
Returns an array of scalar values that correspond to specified percentile values. It can be used in the $group or $setWindowFields stage or as an aggregation expression in $project
{
$percentile: {
input: <expression>,
p: [ <expression1>, <expression2>, ... ],
method: <string>
}
}
Atlas Search Index Management
You can now manage Atlas Search indexes with mongosh methods and database commands.
### mongosh Methods
- db.collection.createSearchIndex() Creates an Atlas Search index on a specified collection.
- db.collection.dropSearchIndex() Deletes an existing Atlas Search index.
- db.collection.getSearchIndexes() Returns information about existing Atlas Search indexes on a specified collection.
- db.collection.updateSearchIndex() Updates an existing Atlas Search index.
Database Commands
- createSearchIndexes Creates one or more Atlas Search indexes on a specified collection.
- dropSearchIndex Deletes an existing Atlas Search index.
- updateSearchIndex Updates an existing Atlas Search index.
Delete support in Time Series
Starting in MongoDB 5.1, you can perform limited delete operations on time series collections. MongoDB 7.0 removes most limitations from operations the restriction remaining is that you cannot use these commands with multi-document transactions: