MongoDB time-series indexes and metaField design
Parent: Global AI Hub Research Corpus · Published reference · snapshot 2026-10-19
↓ Facts as markdownall context files
Time series collections support [secondary indexes](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) on the field specified as the `metaField`. If the data model of your time series data does not have a designated field for your metadata, you can transform your data to create one. To transform the data in your existing coll (from www.mongodb.com)
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Definitions
- Text indexes and unique indexes are not supported on time series collections. [source]
- The bucket catalog is an in-memory cache in WiredTiger that tracks open buckets to coordinate concurrent writes. Its memory use grows with the number of distinct metaField values open at once. [source]
- In the example above, `timestamp` is the name of the `timeField` and `sensorId` is the name of the `metaField`. The value of the `timeField` field must be a [date](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-date) type. [source]
- In the example above, `time` is the name of the `timeField` and `sensor` is the name of the `metaField`. The value of the `timeField` field must be a [date](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-date) type. [source]
- If your deployment is not in one of those cases, use [Database Tools](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#std-label-migrate-data-into-a-timeseries-collection-with-tools) to migrate your data. [source]
- - Data in the filesystem cache is the same as the on-disk format, including benefits of any compression for data files. The filesystem cache is used by the operating system to reduce disk I/O. [source]
- - Positional operators are not supported. A field name like "values.1" denotes a sub-field called "1" in the `values` array. It does not refer to the item at index 1 in the `values` array. [source]
- Make sure you are not performing [DDL operations](https://www.mongodb.com/docs/manual/reference/ddl-operations.md#std-label-ddl-operations) while conducting the rolling index build. [source]
- The document is not indexed if all of the fields in the compound wildcard index are missing. [source]
- - The following fields in the `indexes` array are not available in Stable API V1: [source]
- - If any field in a compound index is an array, no field in that index can use a hashed index. This includes non-array fields. [source]
- - Creating, hiding, and dropping indexes is not permitted in MongoDB Compass Readonly Edition. [source]
- If there is an invalid secondary TTL index, you must manually modify the secondary index to use automatic TTL deletion. [source]
- "Swappiness" is a Linux kernel setting that influences the behavior of the Virtual Memory manager. The `vm.swappiness` setting ranges from `0` to `100`: the higher the value, the more strongly it prefers swapping memory pages to disk over dropping pages from RAM. [source]
- For example, in the following document, `metadata` is a good choice of `metaField` since it makes it easy to query data from a given weather sensor. Using these fields, MongoDB buckets readings from a single sensor together. [source]
- The bucket catalog is a specialized in-memory cache in [WiredTiger](https://www.mongodb.com/docs/manual/core/wiredtiger.md#std-label-storage-wiredtiger). It tracks buckets to minimize latency and coordinate concurrent writes. [source]
- The expiration threshold is the `timeField` field value plus the specified number of seconds. Consider the following document in the `weather24h` collection: [source]
- - The `granularity` is not fine enough to evenly distribute documents into the specified number of `buckets`. [source]
- If the `groupBy` expression refers to an array or document, the values are arranged using the same ordering as in [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) before determining the bucket boundaries. [source]
- The bucket catalog is a specialized in-memory cache in WiredTiger. It tracks buckets to minimize latency and coordinate concurrent writes. [source]
- `$lookup` performance depends on the type of operation performed. Refer to the following table for performance considerations for different `$lookup` operations. [source]
Structure and components
- | Field | Description | | --- | --- | | `db` | The output database name. For a [replica set](https://www.mongodb.com/docs/manual/replication.md#std-label-replica-set) or a standalone, if the output database does not exist, `$out` also creates the database. | | `coll` | The output collection name. | | `timeseries` | A document that specifies the configuration to use when writing to a time series collection. The `timeField` is required. All other fields are optional. | | `timeField` | Required when writing to a time series collection. The name of the field which contains the date in each time se [source]
- | Field | Type | Description | | --- | --- | --- | | `timeseries.timeField` | string | Required. The name of the field which contains the date in each time series document. Documents in a time series collection must have a valid BSON date as the value for the `timeField`. | | `timeseries.metaField` | string | Optional. The name of the field which contains metadata in each time series document. The metadata in the specified field should be data that is used to label a unique series of documents. The metadata should rarely, if ever, change The name of the specified field may not be `_id` or the [source]
- Time series documents can contain a `metaField`. MongoDB uses the `metaField` to group documents for storage optimization and query efficiency. For more information about the `metaField`, see [metaField Considerations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-considerations.md#std-label-timeseries-metafield-considerations) [source]
- | Field | Type | Returned with default query | Description | | --- | --- | --- | --- | | `ns` | string | true | The full namespace of the collection, in the format `"<dbName>.<collectionName>"`. | | `db` | string | true | Name of the database where the collection is located. | | `type` | string | true | Type of data store. Returns `collection` for [collections](https://www.mongodb.com/docs/manual/core/databases-and-collections/#collections), `view` for [views](https://www.mongodb.com/docs/manual/core/views/), and `timeseries` for [time series collection.](https://www.mongodb.com/docs/manual/co [source]
- If your time series collection contains documents with `timeField` timestamps before `1970-01-01T00:00:00.000Z` or after `2038-01-19T03:14:07.000Z`, create an index on the `timeField` to optimize queries. [source]
- 1. Define the `timeField` as the field that contains time data and the `metaField` as the field that contains metadata. [source]
- The `timefield` contains the time data and the `metaField` contains the metadata. The `TimeSeriesOptions` object stores the `timeField`. [source]
- The `timefield` contains the time data and the `metaField` contains the metadata. [source]
- Starting in 9.0, MongoDB stores time series collections in single namespaces that contain the data compressed into organized groups, or [buckets](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucketing-specifics). When you query a time series collection, MongoDB converts the data from its raw bucketed form to a logical form with one document per measurement. [source]
- For time series collections, the output contains `granularity`, `bucketMaxSpanSeconds`, and `bucketRoundingSeconds` parameters, if present. [source]
- - Select fields that rarely or never change as part of your metaField. [source]
- - If possible, select identifiers or other stable values that are common in filter expressions as part of your metaField. [source]
- - Avoid selecting fields that are not used for filtering as part of your metaField. Instead, use those fields as measurements. [source]
- - If possible, insert data that contains identical `metaField` values in the same batches. [source]
- In this case, setting the `granularity` to `hours` groups up to a month's worth of data ingest events into a single bucket, resulting in longer traversal times and slower queries. Setting it to `seconds` leads to multiple buckets per polling interval, many of which might contain only a single document. [source]
- If your data contains empty objects, arrays, or strings, omit the empty fields from your documents to optimize compression. [source]
- If your workload has high cardinality, flattening nested objects may improve performance. For example, the following document contains the same data as the previous document but in a flattened format: [source]
- If the `movies` collection contains an index `{ year: 1, title: 1 }`, the following pipeline can use that index to find the first document of each group: [source]
- - Wildcard indexes are [sparse](https://www.mongodb.com/docs/manual/core/index-sparse.md#std-label-index-type-sparse). They only include entries for documents that contain the indexed field. [source]
- When run on [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos), indexes can only cover queries on [sharded](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-shard) collections if the index contains the shard key. [source]
- The `moviesByYearAndRating` collection will contain documents with movie statistics by year (`year` field) and content rating (shard key); specifically, the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) identifier is `["year", "rated"]` (the ordering of the fields does not matter). Because `$merge` requires a unique index with keys that correspond to the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) identifier fields, create the unique index (the ordering of the fields do not matter):& [source]
- Starting in MongoDB 5.3, if the query planner selects a [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) for a [clustered collection](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) and the query contains bounds that define the portion of the index to search, the explain result includes a `CLUSTERED_IXSCAN` stage. The stage includes information about the clustered index key and index bounds. [source]
- If the query planner selects a [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) for a [clustered collection](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) and the query *does not* contain bounds, the query performs an unbounded collection scan and the explain result includes a `COLLSCAN` stage. [source]
- If the query planner selects a clustered index for a clustered collection and the query does not contain bounds, the query performs an unbounded collection scan and the explain result includes a COLLSCAN stage. [source]
- - If your data model does not contain a single field with high cardinality, consider creating a [compound hashed index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed/create.md#std-label-compound-hashed-index-example). A compound hashed index provides more unique indexed values and can increase cardinality. [source]
- | `$lookup` Operation | Performance Considerations | | --- | --- | | [Equality Match with a Single Join](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#std-label-lookup-single-equality-example) | `$lookup` operations that perform equality matches with a single join perform better when the foreign collection contains an index on the `foreignField`.IMPORTANT: If a supporting index on the `foreignField` does not exist, a `$lookup` operation that performs an equality match with a single join likely has poor performance. | | [Uncorrelated Subqueries](https://www.mongod [source]
- - The [query document](https://www.mongodb.com/docs/manual/tutorial/query-documents.md#std-label-read-operations-query-argument) should only contain a single condition on the array field to which it is applied. Multiple conditions may override each other internally and lead to undefined behavior. [source]
- `$merge` can replace an existing document in the output collection if the aggregation results contain a document or documents that match based on the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) specification. As such, `$merge` can replace all documents in the existing collection if the aggregation results include matching documents for all existing documents in the collection and you specify ["replace"](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-whenMatched-replace) for [whenMatched.](http [source]
- MongoDB is designed for commodity hardware and has few hardware requirements or limitations. MongoDB's core components run on little-endian hardware, primarily x86/x86\_64 processors. Client libraries (drivers) can run on big or little endian systems. [source]
- The default WiredTiger internal cache size value assumes that there is a single [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance per machine. If a single machine contains multiple MongoDB instances, decrease the setting to accommodate the other [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances. [source]
- For improved performance, consider separating your database's data, journal, and logs onto different storage devices, based on your application's access and write pattern. Mount the components as separate filesystems and use symbolic links to map each component's path to the device storing it. [source]
- If `tcmallocReleaseRate` is a small non-zero value, the actual memory release rate can exceed the configured value. TCMalloc releases memory at page-span granularity, and a page span can consist of multiple TCMalloc pages. [source]
- For example, with a granularity of `seconds`, MongoDB buckets documents within the same hour. If a bucket contains a document with a `metaField` value of `sensorA` and a `timeField` value of `2024-08-01T18:23:21Z`, an incoming document with a `metaField` of `sensorB` goes into a separate bucket regardless of time. An incoming document from `sensorA` goes into the same bucket only if its `timeField` is between `2024-08-01T18:00:00Z` and `2024-08-01T18:59:59Z`. [source]
- Do not rely on root-level dollar-prefixed field names that collide with reserved internal metadata field names, as those fields may be dropped or inaccessible in some query-processing contexts. For restrictions and guidance on field names that contain dollar signs (`$`) or periods (`.`), see [Field Names with Periods and Dollar Signs.](https://www.mongodb.com/docs/manual/core/dot-dollar-considerations.md#std-label-crud-concepts-dot-dollar-considerations) [source]
- Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries and outputs a document per each bucket. Each output document contains an `_id` field whose value specifies the inclusive lower bound of the bucket. The [output](https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket.md#std-label-bucket-output) option specifies the fields included in each output document. [source]
- | Field | Type | Description | | --- | --- | --- | | `groupBy` | expression | An [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) to group documents by. To specify a [field path](https://www.mongodb.com/docs/manual/core/aggregation-pipeline.md#std-label-agg-quick-ref-field-paths), prefix the field name with a dollar sign `$` and enclose it in quotes. | | `buckets` | integer | A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. | | `output` | document | Optional. A document that sp [source]
- If you set `scoreDetails` to `true`, `$score` creates a `scoreDetails` metadata field for each document. The `scoreDetails` field contains information about the final ranking. [source]
- | Field | Type | Description | | --- | --- | --- | | `input` | Object | Defines the input that `$rankFusion` ranks. | | `input.``pipelines` | Object | Contains a map of pipeline names to the aggregation stages that define that pipeline. `input.pipelines` must contain at least one pipeline. All pipelines must operate on the same collection and must have a unique name. For more information on input pipeline restrictions, see [Input Pipelines](https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankfusion.md#std-label-rankFusion-input-pipelines) and [Input Pipeline Names.](https:// [source]
- This example uses an `orders` collection, which contains documents describing product orders. Because each order contains multiple products, the first step of the aggregation unpacks the products array into individual product order documents. [source]
- - The `borough` field contains a string indicating the borough in which the restaurant is located. The cardinality is low enough that Compass can provide a graded bar of the field contents, with the most-frequently occurring string on the left. [source]
- For each field, Compass displays summary information about the data type or types the field contains and the range of values. Depending on the data type and the level of cardinality, Compass displays histograms, graded bars, geographical maps, and sample data to provide a sense of the shape and scope of the data contained in each field. [source]
- Contains counts for each cardinality estimation method used during cost-based ranking. Each field represents the number of times a particular estimation method was used. [source]
How it works
- Last point queries are most performant when they use the [DISTINCT\_SCAN optimization](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results). This optimization is only available when an index on `timeField` is descending. [source]
- Last-point queries (latest measurement per metaField value) use $sort { meta: 1, time: -1 } then $group with $first. They are fastest with DISTINCT_SCAN, which the docs say is available only when the index on timeField is descending; confirm via explain('executionStats') showing DISTINCT_SCAN. [source]
- Because buckets group by exact metaField value, many unique metaField values produce many sparse buckets, which lowers query efficiency; pushdown then prunes fewer useful buckets. [source]
- Sort on {timeField: ±1} uses a secondary index on the timeField. Sort on {metaField: ±1, timeField: ±1} uses the default compound index. A sort on the timeField uses a {metaField, timeField} index when the query has a point predicate on the metaField. [source]
- Explain output for a time series query shows a $_internalUnpackBucket stage and, even when the predicate was pushed down, a separate $match stage still appears afterward to re-check unpacked documents. Do not read the residual $match as proof that pushdown failed. [source]
- Per MongoDB docs, a sort on { timeField: ±1 } uses a secondary index on timeField; a sort on { metaField: ±1, timeField: ±1 } uses the default compound index; a sort on { timeField: ±1 } uses a { metaField, timeField } compound index only when the query has a point predicate on metaField. [source]
- - If there are secondary indexes for the clustered collection, the collection has a larger storage size. This is because secondary indexes on a clustered collection with large clustered index keys may have a larger storage size than secondary indexes on a non-clustered collection. [source]
- MongoDB uses the `metaField` to partition data for efficient organization and retrieval. When you create a time series collection, MongoDB groups documents into buckets. Documents within a bucket share an identical `metaField` value and have `timeField` values that are close together. [source]
- When you insert data into a time series collection, the internal collection automatically organizes the data into an optimized storage format using [buckets](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucketing-specifics). If a suitable bucket exists, MongoDB inserts new data into that bucket. If a suitable bucket does not exist, MongoDB creates a new bucket. To optimize storage, choose a `metaField` that rarely changes to create time series collections with fewer, more densely packed buckets. [source]
- When you create a time series collection, MongoDB groups incoming time series data into buckets. By accurately setting granularity, you control how frequently data is bucketed based on the ingestion rate of your data. [source]
- All time series collection use a compressed bucket format when you append data into opened or reopened buckets. Compressing time series data in the cache supports high [cardinality](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-cardinality) workloads while preserving efficient query performance. [source]
- Index hints cause MongoDB to use a specific index for a query. Some operations on time series collections can only take advantage of an index if that index is specified in a hint. [source]
- For example, the following query causes MongoDB to use the `timestamp_1_metadata.sensorId_1` index: [source]
- The Query Profiler samples operations by using a bucketing algorithm that adjusts the sample size based on the width of the selected time range. Because of differences in bucket size, a wider time range might display fewer sampled operations than a narrower time range. For exact, unsampled operation counts, download your `mongod` logs. To learn more, see [View and Download MongoDB Logs.](https://www.mongodb.com/docs/atlas/mongodb-logs.md#std-label-mongodb-logs) [source]
- Bucket count depends on the number of unique metaField values, because documents share a bucket only if their metaField values match exactly (for object/array metaFields, all fields/elements must match). [source]
- Some operations on a time series collection only use an index when it is passed as a hint. A hint can be an index name or a key pattern. [source]
- `{ metaField: ±1, timeField: ±1 }` when there is a point predicate on `<metaField>` [source]
- MongoDB begins removing expired documents or time series buckets as soon as the index finishes building on the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary). For more information on the index build process, see [Index Builds on Populated Collections.](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-operations) [source]
- You can specify a `partialFilterExpression` option for all MongoDB [index types](https://www.mongodb.com/docs/manual/core/indexes/index-types.md#std-label-index-types). When specifying a `partialFilterExpression` for a TTL index on a time series collection, you can only filter on the collection `metaField`. [source]
- 3. Optionally, set `ExpireAfter` to expire documents when the value of the `timeField` reaches the specified interval. Expired documents are automatically deleted: [source]
- Optionally, set `expireAfter` to expire documents when the value of the `timeField` reaches the specified interval. Expired documents are automatically deleted. [source]
- 3. Optionally, set `expireAfterSeconds` to expire documents when the value of the `timeField` reaches the specified interval. Expired documents are automatically deleted. [source]
- Optionally, set `expireAfterSeconds` to expire documents when the value of the `timeField` reaches the specified interval. Expired documents are automatically deleted. [source]
- - A sort on `{ <timeField>: ±1 }` uses a secondary index on `{ metaField: ±1, timeField: ±1 }` when there is a point predicate on `<metaField>`. [source]
- You can use the `granularity` parameter to specify how frequently MongoDB buckets your time series data based on the data ingestion rate. The following table shows the maximum time interval included in one bucket of data when using a given `granularity` value: [source]
- You must be running MongoDB 5.0.1 or later in order to change a time series collection's granularity after the collection has been created. [source]
- Using an array as a `metaField` may cause unexpected collection behavior because array equality depends on specific order. [source]
- The following operation inserts six documents, but only incurs the cost of two inserts (one per `metaField` value), because the documents are ordered by sensor. The `ordered` parameter is set to `false` to improve performance: [source]
- The following table shows the maximum time interval included in one bucket of data when using a given `granularity` value: [source]
- `coordinates` fields with populated values and `coordinates` fields with an empty array result in a schema change for the compressor. The schema change causes the second and third documents in the sequence to remain uncompressed. [source]
- In some instances, such as when running in a container that is configured to use less RAM than the amount of memory provisioned for the host, you must account for the limits. You may need to configure the WiredTiger cache to an appropriate value, as WiredTiger may not account for the memory limits of the specific container in certain cases. [source]
- When using encryption, CPUs equipped with AES-NI instruction-set extensions show significant performance advantages. If you are using MongoDB Enterprise with the [Encrypted Storage Engine](https://www.mongodb.com/docs/manual/core/security-encryption-at-rest.md#std-label-encrypted-storage-engine), choose a CPU that supports AES-NI for better performance. [source]
- Collections with fine-grained or changing `metaField` values generate many sparsely packed, short-lived buckets, increasing the cardinality of your collection. Increasing cardinality leads to decreased storage and query efficiency. [source]
- Granularity must match per-source ingest interval: 'seconds' (1h bucket span) with sparse data leads to buckets with a single document; 'hours' (30-day span) leads to longer traversal. Custom bucketMaxSpanSeconds/bucketRoundingSeconds exist since 6.3. Granularity mismatch compounds metaField cardinality fragmentation. [source]
- For every encrypted collection, MongoDB creates [two metadata collections](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections.md#std-label-qe-metadata-collections), increasing storage space. MongoDB creates an index for each encrypted field, which increases the duration of write operations on that field. When a write operation updates an indexed field, MongoDB updates the related index. [source]
- - Create the indexes that the Performance Advisor suggests when they align with your [Indexing Strategies.](https://www.mongodb.com/docs/manual/applications/indexes/) [source]
- The [`sh.shardCollection()`](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#mongodb-method-sh.shardCollection) method can also create a unique index on the shard key when passed the `{ unique: true }` option if: the shard key is [range-based](https://www.mongodb.com/docs/manual/core/ranged-sharding.md), the collection is empty, and a unique index on the shard key doesn't already exist. [source]
- In the previous example, because the `on` identifier is the shard key and another field, a separate operation to create the corresponding index is required. [source]
- - [Merge the matching documents](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-whenMatched-merge) that results in a document that violates a unique index other than the index on the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field(s). [source]
- `notablescan` does not allow unbounded queries that use a clustered index because the queries require a full collection scan. For more information, see [Collection Scans.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-collection-scan) [source]
- You can only have one clustered index in a collection because the documents can be stored in only one order. Only collections with a clustered index store the data in sorted order. [source]
- - A clustered index can only be created when you create the collection. [source]
- Starting in MongoDB 6.0.7, if a usable clustered index exists, the MongoDB query planner evaluates the clustered index against secondary indexes in the query planning process. When a query uses a clustered index, MongoDB performs a [bounded collection scan.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-bounded-collection-scan) [source]
- In clustered collections with only a default index on the `_ìd` field (no secondary indexes), the index size appears as zero because the collection does not require a separate index file. [source]
- | Counter | Description | | --- | --- | | `collscan``clusteredCollscan` | Collection scans, counted separately based on whether the scan uses the [clustered index.](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) | | `coveredIxscan` | Index scans that don't fetch documents. | | `ixscanFetch` | Index scans that fetch documents. | | `countScan` | Scans that count index keys without returning documents. | | `distinctScan``distinctScanFetch` | Scans that skip duplicate index keys, counted separately based on whether the scan fetches documents. | | [source]
- The [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) parameter does not allow unbounded queries that use a clustered index because the queries require a full collection scan. [source]
- The notablescan parameter does not allow unbounded queries that use a clustered index because the queries require a full collection scan. [source]
- Enabling Queryable Encryption on a collection redacts fields from some diagnostic commands and omits some operations from the query log. This limits the data available to MongoDB support engineers, especially when analyzing query performance. To measure the impact of operations against encrypted collections, use a third party application performance monitoring tool to collect metrics. [source]
- `$group` is a blocking stage, which causes the pipeline to wait for all input data to be retrieved for the blocking stage before processing the data. A blocking stage may reduce performance because it reduces parallel processing for a pipeline with multiple stages. A blocking stage may also use substantial amounts of memory for large data sets. [source]
- | Name | Description | | --- | --- | | [`$accumulator`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator.md#mongodb-group-grp.-accumulator) | Returns the result of a user-defined accumulator function. | | [`$addToSet`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/addtoset.md#mongodb-group-grp.-addToSet) | Returns an array of *unique* expression values for each group. Order of the array elements is undefined. | | [`$avg`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg.md#mongodb-group-grp.-avg) | Returns an average of n [source]
- - Only one array field should appear in the [query document](https://www.mongodb.com/docs/manual/tutorial/query-documents.md#std-label-read-operations-query-argument). Additional array fields in the query document may lead to undefined behavior. [source]
- When used as an accumulator, `$median` always uses an approximation algorithm. As a result, the computed percentiles `$median` returns on the same data set might differ on each run, due to pseudorandomness in the t-digest approximation algorithm. Additionally, `$median` may return a value that differs slightly from the true statistical median. [source]
- Because CSFLE and Queryable Encryption do not provide a mechanism to verify the integrity of a schema, relying on a server-side schema means trusting that the server's schema has not been tampered with. If an adversary compromises the server, they can modify the schema so that a previously encrypted field is no longer labeled for encryption. This causes the client to send plaintext values for that field. [source]
- - When a whole array is sorted, the sort is lexicographic. The aggregation [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) stage, behaves differently. See [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) for more details. [source]
- When specifying [`linearizable read concern`](https://www.mongodb.com/docs/manual/reference/read-concern-linearizable.md#mongodb-readconcern-readconcern.-linearizable-), always use [`maxTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxtimems.md#mongodb-method-cursor.maxTimeMS) in case a majority of data bearing members are unavailable. [source]
- When using [Stable API](https://www.mongodb.com/docs/manual/reference/stable-api.md#std-label-stable-api) V1, all [`createIndexes`](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#mongodb-dbcommand-dbcmd.createIndexes) fields are available with the following exceptions: [source]
- If you're connecting to a multi-cloud MongoDB Atlas deployment through a [private connection](https://www.mongodb.com/docs/atlas/reference/faq/connection-changes.md#std-label-conn-string-options), you can access only the nodes in the same cloud provider that you're connecting from. This cloud provider might not have the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary) node in its region. When this happens, you must specify the [secondary read preference](https://www.mongodb.com/docs/manual/core/read-preference.md#std-label-read-preference) mode in the conne [source]
- When inserting documents with monotonically increasing shard keys, all inserts belong to the same [chunk](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-chunk) on a single [shard](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-shard). The system eventually divides the chunk range that receives all write operations and migrates its contents to distribute data more evenly. However, at any moment the cluster directs insert operations only to a single shard, which creates an insert throughput bottleneck. [source]
- - [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) includes a [Full Time Diagnostic Data Capture](https://www.mongodb.com/docs/manual/administration/full-time-diagnostic-data-capture.md#std-label-ftdc-stub) mechanism to assist MongoDB engineers with troubleshooting deployments. If this thread fails, it terminates the originating process. To avoid the most common failures, confirm that the user running the process has permissions to create the FTDC `diagnostic.data` directory. For `mongod` the directory is within [`storage.dbPath`](https://ww [source]
- - When you use a [`$project`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/project.md#mongodb-pipeline-pipe.-project) aggregation stage it should typically be the last stage in your pipeline, used to specify which fields to return to the client. [source]
- Using a `$project` stage at the beginning or middle of a pipeline to reduce the number of fields passed to subsequent pipeline stages is unlikely to improve performance, because the database performs this optimization automatically. [source]
- When using [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption.md#std-label-qe-manual-feature-qe), the `$planCacheStats` stage omits operations against encrypted collections, even though the operations are cached as normal. [source]
- When the `allHosts` option is set to `false`, [`$planCacheStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/plancachestats.md#mongodb-pipeline-pipe.-planCacheStats) follows the [read preference](https://www.mongodb.com/docs/manual/core/read-preference.md#std-label-read-preference) in selecting the host(s) from which to return the plan cache information. [source]
- For example, in the following aggregation pipeline, [`$project`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/project.md#mongodb-pipeline-pipe.-project) excludes the `_id` field from the documents passed into `$merge`. When `$merge` writes these documents to the `"newCollection"`, `$merge` generates a new `_id` field and value. [source]
- The `$merge` stage can output to a sharded collection. When the output collection is sharded, `$merge` uses the `_id` field and all the [shard key](https://www.mongodb.com/docs/manual/core/sharding-shard-key.md#std-label-sharding-shard-key-creation) fields as the default [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) identifier. If you override the default, the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) identifier must include all the [shard key](https://www.mongodb.com/docs/manual/c [source]
- When [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) outputs to the same collection that is being aggregated, documents may get updated multiple times or the operation may result in an infinite loop. This behavior occurs when the update performed by [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) changes the physical location of documents stored on disk. When the physical location of a document changes, [`$merge`](https://www.mongodb.com/docs/manual/referenc [source]
- When used as an accumulator, `$percentile` always uses an approximation algorithm. Due to pseudorandomness in the t-digest approximation algorithm, the computed percentile values on the same data set might differ on each run. Additionally, `$percentile` may return values that differ slightly from the true statistical percentiles. [source]
- - Atlas displays top namespaces by default. Depending on the time range, a namespace might fall in and out of the monitored list. Atlas interpolates missing data when at least one host metric exists in both ends of the time range. If Atlas encounters missing data, dotted lines connect the available data points. [source]
- The `numad` daemon process can also reduce [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) performance. You should ensure `numad` is not enabled on MongoDB servers. [source]
- MongoDB performs best where swapping can be avoided or kept to a minimum, as retrieving data from swap will always be slower than accessing data in RAM. However, if the system hosting MongoDB runs out of RAM, swapping can prevent the Linux OOM Killer from terminating the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) process. [source]
- With the WiredTiger storage engine, WiredTiger objects may be stored on remote file systems if the remote file system conforms to ISO/IEC 9945-1:1996 (POSIX.1). Because remote file systems are often slower than local file systems, using a remote file system for storage may degrade performance. [source]
- When running MongoDB in production on Linux, you should use Linux kernel version 2.6.36 or later, with either the XFS or EXT4 filesystem. If possible, use XFS as it generally performs better with MongoDB. [source]
- With the [WiredTiger storage engine](https://www.mongodb.com/docs/manual/core/wiredtiger.md#std-label-storage-wiredtiger), using XFS is **strongly recommended** for data bearing nodes to avoid performance issues that may occur when using EXT4 with WiredTiger. [source]
- - Adjust the `ulimit` settings for your platform according to the recommendations in the [ulimit](https://www.mongodb.com/docs/manual/reference/ulimit.md#std-label-ulimit) reference. Low `ulimit` values will negatively affect MongoDB when under heavy use and can lead to failed connections to MongoDB processes and loss of service. [source]
- Higher readahead commonly benefits sequential I/O operations. Because MongoDB disk access patterns are generally random, if you use higher readahead settings you get limited benefit and it can degrade performance. For optimal MongoDB performance, set readahead between 8 and 32, unless testing shows a measurable, repeatable, and reliable benefit from a higher value. [MongoDB commercial support](https://support.mongodb.com/welcome) can advise on alternate readahead configurations. [source]
- VMware supports *memory overcommitment*, where you can assign more memory to your virtual machines than the physical machine has available. When memory is overcommitted, the hypervisor reallocates memory between the virtual machines. VMware's balloon driver (`vmmemctl`) reclaims the pages that are considered least valuable. [source]
- The balloon driver resides inside the guest operating system. Under certain configurations, when the balloon driver expands, it can interfere with MongoDB's memory management and affect MongoDB's performance. [source]
- You should also consider typical queries when choosing the `granularity` value. For example, if you expect your queries to fetch 1 day of data at a time, use "minutes". A finer granularity, like "seconds", creates buckets that cover one hour. This requires more buckets to represent the same data, which negatively affects storage and query performance. A coarser granularity, like "hours" (which has a 30-day bucket span), requires queries to fetch 30 days of data at a time and then filter out most of it. [source]
- For each open bucket, the catalog maintains information such as the `metaField`, active writers, covered time span, number of documents, size, and recent operations. Because MongoDB creates separate buckets for documents with a different `metaField`, multiple buckets are typically open at the same time. [source]
- When metrics data reach the end of their retention period, Atlas compacts them into a single unit of the next broader granularity level. [source]
- When you scale a cluster to M40 tier or higher, the cluster qualifies for premium monitoring. To view historical metrics data for your scaled cluster, you must adjust the granularity to one-minute intervals. This is because premium monitoring displays 10-second metrics granularity while basic monitoring displays 1-minute granularity. [source]
- - `bucketRoundingSeconds` sets the time interval that determines the starting timestamp for a new bucket. When a document requires a new bucket, MongoDB rounds down the document's timestamp value by this interval to set the minimum time for the bucket. [source]
- The results in the following table demonstrate how different values for `granularity` yield different bucket boundaries: [source]
- When you set `scoreDetails` to `true`, `$score` sets the `scoreDetails` metadata field for each document but does not automatically output the `scoreDetails` metafield. [source]
- When you set `scoreDetails` to `true`, `$rankFusion` sets the `scoreDetails` metadata field for each document but does not automatically output the `scoreDetails` metafield. [source]
- - Otherwise, Atlas retrieves metrics at regular intervals based on [granularity](https://www.mongodb.com/docs/atlas/monitor-cluster-metrics.md#std-label-monitoring-storage-granularity). When the retrieved metrics indicate that an alert condition is met, Atlas tracks the alert condition until it ends, or until it remains past the amount of time specified in the send if condition lasts at least field. [source]
- When unset, `contention` defaults to `8`, which provides high performance for most workloads. Higher contention improves the performance of insert and update operations on low cardinality fields, but decreases find performance. [source]
- When implementing an application that uses Queryable Encryption, consider the points listed in [Security Considerations.](https://www.mongodb.com/docs/manual/core/queryable-encryption/about-qe-csfle.md#std-label-qe-csfle-security-considerations) [source]
- - Use an odd number of voting members to ensure that elections proceed successfully. You can have up to 7 voting members. If you have an *even* number of voting members, and constraints, such as cost, prohibit adding another secondary to be a voting member, you can add an [arbiter](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-arbiter) to ensure an odd number of votes. For additional considerations when using an arbiter for a 3-member replica set (P-S-A), see [Replica Set Arbiter.](https://www.mongodb.com/docs/manual/core/replica-set-arbiter.md) [source]
- When using [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption.md#std-label-qe-manual-feature-qe), CRUD operations against encrypted collections are omitted from the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection. For details, see [Redaction.](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/limitations.md#std-label-qe-redaction) [source]
- Free clusters and Flex clusters only trigger alerts related to the metrics supported by those clusters. For complete documentation on Free clusters and Flex clusters alert and metric limitations, see [Atlas Free Cluster Limits](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations.md#std-label-atlas-free-tier), and [Atlas Flex Limitations.](https://www.mongodb.com/docs/atlas/reference/flex-limitations.md#std-label-flex-cluster-limitations) [source]
- This section describes considerations when running MongoDB in some of the more common virtual environments. [source]
- Specify the `encryptedFieldsObject` when you create the collection, and also when you create a client to access the collection. For more information about the security considerations of not defining the `encryptedFieldsObject`, see [Security Considerations.](https://www.mongodb.com/docs/manual/core/queryable-encryption/about-qe-csfle.md#std-label-qe-csfle-security-considerations) [source]
How-to and procedures
- To improve query performance, [create one or more secondary indexes](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) on your `timeField` and `metaField` to support common query patterns. In versions 6.3 and higher, MongoDB creates a secondary index on the `timeField` and `metaField` automatically. [source]
- To improve query performance for [time series collections](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-time-series-collection), add one or more [secondary indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) to support common time series query patterns. Starting in MongoDB 6.3, MongoDB automatically creates a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on the `metaField` and `timeField` fields for new collections. [source]
- To confirm that the last point query used the secondary index, run the operation again using `explain`: [source]
- To confirm that the last point query used the secondary index, run the operation again using `.explain( "executionStats" )`: [source]
- To learn how to optimize compression, see [Compression Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-compression) [source]
- To improve query performance, you can manually [add secondary indexes](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) to any field in your time series collection. [source]
- To convert a collection from custom bucketing to a `granularity`, value, both `bucketMaxSpanSeconds` and `bucketRoundingSeconds` must be less than or equal to the `granularity` equivalent: [source]
- To learn how to optimize inserts for large operations, see [Inserts Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-inserts) [source]
- To query the `metaField` for a single time series: [source]
- To modify the [granularity](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity) of a time series collection, you can increase `timeseries.granularity` from a shorter unit of time to a longer one: [source]
- To modify the granularity of a **sharded** time series collection, you must be running MongoDB 6.0 or later. [source]
- To learn how to optimize queries on your time series collection, see [Query Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-query-performance) [source]
- Ensure that your [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) is large enough to permit the indexing or re-indexing operation to complete without falling too far behind to catch up. See the [oplog sizing](https://www.mongodb.com/docs/manual/core/replica-set-oplog.md#std-label-replica-set-oplog-sizing) documentation for additional information. [source]
- Create a secondary single-field index on the `timestamp` field: [source]
- To create [unique indexes](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique) using the following procedure, you must stop all writes to the collection during this procedure. [source]
- To start an index build with a non-default commit quorum, specify the [commitQuorum.](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#std-label-createIndexes-cmd-commitQuorum) [source]
- Use the [`setIndexCommitQuorum`](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#mongodb-dbcommand-dbcmd.setIndexCommitQuorum) command to modify the commit quorum of an in-progress index build. [source]
- To create a `text` or `2d` index on a collection that has a non-simple collation, you must explicitly specify `{collation: {locale: "simple"} }` when creating the index. [source]
- To confirm that the sort operation used the Secondary Index, run the operation again with the `explain` option: [source]
- To confirm that the sort operation used the Secondary Index, run the operation again with the `.explain( "executionStats" )` option: [source]
- To learn how to create a collection with a clustered index, see [Date Clustered Index Key Example.](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections-index-example) [source]
- To specify criteria on multiple fields of documents inside that array, use the [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/query/elemmatch.md#mongodb-query-op.-elemMatch) query operator. The following query returns the first document inside a `grades` array that has a `mean` of greater than 70 and a `grade` of greater than 90. [source]
- To avoid this constraint, use a [hashed shard key](https://www.mongodb.com/docs/manual/core/hashed-sharding.md#std-label-sharding-hashed-sharding) or select a field that does not increase or decrease monotonically. [source]
- To learn which MongoDB server products and drivers support Queryable Encryption, see [Compatibility.](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/compatibility.md#std-label-qe-compatibility-reference) [source]
- To view statistics on the cache and eviction rate, see the [`wiredTiger.cache`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.wiredTiger.cache) field returned from the [`serverStatus`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-dbcommand-dbcmd.serverStatus) command. [source]
- Use [Premium Storage](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-block-blob-premium). Microsoft Azure offers two general types of storage: Standard storage, and Premium storage. MongoDB on Azure has better performance when using Premium storage than it does with Standard storage. [source]
- To prevent negative performance impact from the balloon driver and memory overcommitment features, reserve the full amount of memory for the virtual machine running MongoDB. Reserving the appropriate amount of memory for the virtual machine prevents the balloon from inflating in the local operating system when there is memory pressure in the hypervisor. [source]
- To avoid inconsistencies caused by race conditions, buckets may be closed and removed from the bucket catalog when a conflicting operation is executed. Restarting [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) closes all buckets and resets the bucket catalog. [source]
- Set the `timeField` and `metaField`. You can optionally set the `granularity` field. [source]
- To query the `timeField` for a time span: [source]
- Set the `timeField`, `metaField`, and `granularity`: [source]
- To use the self-querying retriever, you must describe the documents in your collection and the metadata fields that you want to filter on. This information helps the LLM understand the structure of your data and how to filter results based on user queries. [source]
- To use custom bucketing parameters, set both parameters to the same value, and do not set `granularity`: [source]
- Set `granularity` to `R5`, `R10`, `R20`, `R40`, or `R80` to restrict bucket boundaries to values in the series. The values of the series are multiplied by a power of 10 when the `groupBy` values are outside of the 1.0 to 10.0 (10.3 for `R80`) range. [source]
- Set `granularity` to `E6`, `E12`, `E24`, `E48`, `E96`, or `E192` to restrict bucket boundaries to values in the series. The values of the series are multiplied by a power of 10 when the `groupBy` values are outside of the 1.0 to 10.0 range. To learn more about the E-series and their respective relative errors, see [preferred number series](https://en.wikipedia.org/wiki/Preferred_number). [source]
- Set `granularity` to `1-2-5` to restrict bucket boundaries to various powers of the third root of 10, rounded to one significant digit. [source]
- Set `granularity` to `POWERSOF2` to restrict bucket boundaries to numbers that are a power of two. [source]
- To view the `scoreDetails` metadata field, you must either: [source]
- Avoid specifying **only** the `timeField` as the shard key. Since the `timeField` [increases monotonically](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key.md#std-label-shard-key-monotonic), it may result in all writes appearing on a single chunk within the cluster. Ideally, data is evenly distributed across chunks. [source]
- Set a Strategic metaField When Creating the Collection [source]
- Use Standard Embedded Fields Best Practices [source]
Examples and snippets
- ```csharp — `// Indexes on ``timeField`` descending are more performant because they` … [source]
- ```java — `// Indexes on ``timeField`` descending are more performant because they` … [source]
- ```javascript — `// Indexes on ``timeField`` descending are more performant because they` … [source]
- ```python — `# Indexes on ``timeField`` descending are more performant because they` … [source]
- ```csharp — `_collection?.Indexes.CreateOne(` … [source]
- ```text — `"explainVersion": "1",` … [source]
- ```java — `var explainCommand = new Document("explain", new Document()` … [source]
- ```java — `collection.createIndex(Indexes.compoundIndex(` … [source]
- ```java — `var pipeline = Arrays.asList(` … [source]
- ```javascript — `db.createCollection(` … [source]
- ```javascript — `db.sensorData.aggregate( [` … [source]
- ```javascript — `db.getCollection( 'sensorData' ).explain( "executionStats" ).aggregate( [` … [source]
- ```javascript — `const createCollectionOptions = {` … [source]
- ```javascript — `const pipeline = [` … [source]
- ```python — `database.create_collection(` … [source]
- ```python — `pipeline = [` … [source]
- ```java — `var hintPipeline = Arrays.asList(` … [source]
- ```javascript — `const hintPipeline = [` … [source]
- ```csharp — `var createCollectionOptions = new CreateCollectionOptions` … [source]
- ```java — `CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions()` … [source]
- ```csharp — `var timeSeriesOptions = new TimeSeriesOptions(` … [source]
- ```javascript — `const settings = {` … [source]
- ```javascript — `db.runCommand( {` … [source]
- ```java — `Document createCommand = new Document("create", "weather24h")` … [source]
- ```javascript — `const createCommand = {` … [source]
- ```python — `create_command = {` … [source]
- ```javascript — `cursor: {` … [source]
- ```javascript — `db.weather.findOne( {` … [source]
- ```javascript — `_id: ObjectId("<object-id>"),` … [source]
- ```javascript — `timestamp: ISODate("2020-01-23T00:00:00.441Z"),` … [source]
- ```javascript — `timestamp: ISODate("2024-06-17T10:00:00Z"),` … [source]
- ```csharp — `await _collection?.Indexes.CreateOneAsync(new CreateIndexModel<BsonDocument>(` … [source]
- ```csharp — `_collection?.Indexes.CreateOne(new CreateIndexModel<BsonDocument>(` … [source]
- ```java — `.append("metadata", new Document()` … [source]
- ```java — `List<Document> sampleDocuments = Arrays.asList(` … [source]
- ```java — `collection.createIndex(Indexes.ascending("timestamp"));` … [source]
- ```java — `var matchFilter = Filters.gte("timestamp",` … [source]
- ```java — `collection.createIndex(Indexes.geo2dsphere("metadata.location"));` … [source]
- ```javascript — `const sampleDocuments = [` … [source]
- ```javascript — `const matchStage = {` … [source]
- ```python — `sample_documents = [` … [source]
- ```python — `match_stage = {"$match": {"timestamp": {"$gte": datetime(2022, 1, 15, 0, 0, 0, tzinfo=timezone.utc)}}}` … [source]
- ```javascript — `"ok" : 0,` … [source]
- ```javascript — `"numIndexesBefore" : 2,` … [source]
- ```javascript — `_id: ObjectId("<object-id>"),` … [source]
- ```javascript — `range: 1,` … [source]
- ```javascript — `db.newDailyCommentCount.createIndex(` … [source]
- ```javascript — `"timestamp": ISODate("2025-08-19T12:00:00Z"),` … [source]
- ```json — `"processorName": "<stream-processor-name>",` … [source]
Measurements and reference values
- The official docs make no numeric performance claim. They say only that the gain varies with workload and instance configuration. The vendor blog's 10-100x figures are therefore workload-specific best cases and should not be assumed for other pipelines. [source]
- A bucket closes when the set of active buckets does not fit within the allowed storage engine cache size, or when the bucket catalog exceeds its memory allocation (default 2.5% of system memory). The docs point to collStats for reviewing this. [source]
- For any configuration of granularity parameters, the maximum size of a bucket is 1000 measurements or 125KB of data, whichever is lower. MongoDB may also enforce a lower maximum size for high cardinality data with many unique values, so that the working set of buckets fits within the [WiredTiger cache.](https://www.mongodb.com/docs/manual/core/wiredtiger.md#std-label-storage-wiredtiger) [source]
- A new bucket is created when the metaField matches no active bucket, the timestamp is outside all active buckets' ranges, or the doc exceeds remaining size/count limits. Buckets close at 1000 docs by default, 125KiB size cap, when the active bucket set exceeds storage-engine cache, or when the bucket catalog exceeds its memory allocation (default 2.5% of system memory). High cardinality means many open buckets and so earlier closures. [source]
- Community report: on 6.0.5 with metaField=userid, granularity=hours, ~40B events/3TB, reads and writes degraded after ~3 weeks; one user had 3,120 buckets for 20,539 docs, dropping to 370 after read/delete/re-insert, giving >10x faster queries. A second user reported ~10s for a project/group over ~6M records. No MongoDB staff answer or confirmed fix in the thread. [source]
- For example, on a system with a total of 4GB of RAM the WiredTiger cache uses 1.5GB of RAM (`0.5 * (4GB - 1GB) = 1.5 GB`). When providing a specific cache size ensure the RAM does not exceed the bounds of 0.256GB to 10000GB. [source]
- - A clustered index supports keys up to 8 MB in size, but a much smaller clustered index key is best. [source]
- Commodity (SATA) spinning drives are often a good option, as the random I/O performance increase with more expensive spinning drives is not that dramatic (only on the order of 2x). Using SSDs or increasing RAM may be more effective in increasing I/O throughput. [source]
- - The bucket catalog exceeds its allowed total memory allocation (by default, 2.5% of available system memory) [source]
Problems, failure modes and limitations
- Since MongoDB 6.3 the server automatically creates a compound index on the metaField and timeField for new time series collections. No index exists on _id; a hint on _id fails unless the user creates that index, and in 8.3 an index or hint named "_id_" returns an error. [source]
- Partial indexes work on time series collections. Since 6.0 they accept $or, $in and $geoWithin, but cannot be created on the metaField and timeField. Since 7.0 a TTL index with a partialFilterExpression that depends only on the metaField is allowed. [source]
- distinct() cannot be efficiently indexed on time series collections; use $match on a metaField prefix with $group over a compound metaField index instead. For high-cardinality workloads, flattening nested measurement objects may help, but docs recommend it only if nesting causes significant performance issues. [source]
- On MongoDB 5.0.3, sorting a 10M-document time series collection by timestamp with no index failed with 'Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting'; the author had to add an index to sort by time. [source]
- If your time series collection includes `timeField` values before `1970-01-01T00:00:00.000Z` or after `2038-01-19T03:14:07.000Z`, MongoDB logs a warning and disables some query optimizations that make use of the [internal clustered index](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-internal-index). To regain query performance and resolve the log warning, [create a secondary index](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) on the `timeField`. [source]
- Reported limit: a find with sort {timestamp: -1} and limit 1 on a time series collection did a COLLSCAN on system.buckets.<name> and unpacked about 294,000 documents (server 5.0.6, a secondary index on timestamp existed). An answer from MongoDB staff said usual index improvements do not apply, and pointed to SERVER-4507. A 2025-06-27 post says the issue was still open. The thread does not show whether current releases still behave this way. [source]
- A `metaField` should rarely change and can be any data type. A `metaField` can be an object and can contain subfields. Once you define a field as the `metaField`, you can change the value of the `metaField` but you cannot redefine the `metaField` as another field. For example, if you create time series documents with the `metaField` defined as field `A`, you cannot later convert a field `B` to be the `metaField`. However, if the value of `A` is an object, you can add new subfields to `A`. [source]
- Starting in MongoDB 8.0, the use of the `timeField` as a shard key in time series collections is deprecated. [source]
- Match expressions in update commands can only specify the metaField. You can't update other fields in a time series document. For more details, see [Time Series Update Limitations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#std-label-timeseries-limitations-updates) [source]
- | Metric | Description | | --- | --- | | `numBuckets` | The total number of tracked buckets. Expected to be equal to the sum of `numOpenBuckets` and `numArchivedBuckets`. | | `numOpenBuckets` | The number of tracked buckets with a full representation stored in-cache, ready to receive new documents. | | `numIdleBuckets` | The number of buckets that are open and currently without an uncommitted document insertion pending. A subset of numOpenBuckets. | | `numArchivedBuckets` | The number of tracked buckets with a minimal representation stored in-cache that can be efficiently reopened to receive n [source]
- Due to the unique data structure of time series collections, MongoDB can't efficiently index them for distinct values. Avoid using the [`distinct`](https://www.mongodb.com/docs/manual/reference/command/distinct.md#mongodb-dbcommand-dbcmd.distinct) command or [`db.collection.distinct()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.distinct.md#mongodb-method-db.collection.distinct) helper method on time series collections. Instead, use a [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group) aggregation to group [source]
- Forum reports show a blank-filter sort on timeField descending produces a backward COLLSCAN on system.buckets followed by $_internalUnpackBucket, with multi-second runtimes and memory-limit errors unless allowDiskUse is set; explain on a time series collection reports the bucket collection plan. [source]
- - You cannot hide a clustered index. See [Hidden indexes.](https://www.mongodb.com/docs/manual/core/index-hidden.md) [source]
- For time series collections, the distinct command can't make efficient use of indexes. Instead, use a $group aggregation to group documents by distinct values. For details, see Time Series Limitations. [source]
- You cannot decrease the granularity interval or the custom bucketing values. [source]
- | `granularity` | `bucketRoundingSeconds` limit (inclusive) | `bucketMaxSpanSeconds` limit (inclusive) | | --- | --- | --- | | `seconds` | 60 | 3600 | | `minutes` | 3600 | 86400 | | `hours` | 86400 | 2592000 | [source]
- * You can use the `$geoNear` pipeline operator on any field in a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection). However, you cannot use the `query` field for `$geoNear` on a time series collection. [source]
- After creating a time series collection, you can modify its granularity using the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) method. However, you can only increase the timespan covered by each bucket. You cannot decrease it. [source]
- - **Metadata**: A label or tag that identifies a data series and rarely changes. Metadata is stored in a `metaField`. You cannot add a `metaField` field to a time series document after you create it. Metadata is also known as `source`. For more information, see [metaFields.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-timeseries-collections-metafield) [source]
- Also, starting in MongoDB 8.0, if you create a time series collection with a shard key containing the `timeField`, a [log message](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref) is added to the [log file](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-message-destinations) on the [primary shard](https://www.mongodb.com/docs/manual/core/sharded-cluster-shards.md#std-label-primary-shard). In addition, a log message is added every 12 hours on the primary node of the [config server replica set](https://www.mongodb.com/docs/man [source]
- You cannot downgrade below MongoDB 6.3 if any time series collections explicitly specify the custom bucketing fields `bucketMaxSpanSeconds` and `bucketRoundingSeconds`. If possible, convert to the corresponding `granularity`. If you cannot, you must drop the collection before downgrading. [source]
- | `granularity` | `granularity` bucket limit | | --- | --- | | `seconds` | 1 hour | | `minutes` | 24 hours | | `hours` | 30 days | [source]
- Anti-pattern: using a unique per-device ID (e.g. UUID) as a top-level string metaField makes one bucket per ID per time window (example: 100,000 UUIDs -> 100,000 buckets). The blog suggests grouping attributes (region, device type) with the raw ID as a subfield so region queries still co-locate. Blog advice, not MongoDB-endorsed; blog gives no numeric threshold. [source]
- Anti-pattern: putting measurement values (temperature, CPU) or frequently changing status flags in the metaField forces a new bucket whenever the value changes. [source]
- The Performance Advisor can't suggest indexes for MongoDB databases configured to use the `ctime` timestamp format. As a workaround, set the timestamp format for such databases to either `iso8601-utc` or `iso8601-local`. To learn more about timestamp formats, see [mongod --timeStampFormat.](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--timeStampFormat) [source]
- - You can't create indexes through the Performance Advisor if [Data Explorer](https://www.mongodb.com/docs/atlas/atlas-ui.md#std-label-atlas-ui) is disabled for your project. You can still view the Performance Advisor recommendations, but you must create those indexes from [`mongosh`.](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) [source]
- If you cannot stop all writes to the collection during this procedure, do not use the procedure on this page. Instead, build your unique index on the collection by issuing [`db.collection.createIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#mongodb-method-db.collection.createIndex) on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) for a sharded cluster. [source]
- - The above unsupported index types are ignored by the [query planner](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) in [strict mode](https://www.mongodb.com/docs/manual/reference/stable-api.md#std-label-stable-api-strict-client). For example, attempting to use a `sparse` index with [`cursor.hint()`](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md#mongodb-method-cursor.hint) results in the following `BadValue` error: [source]
- ```text planner returned error :: caused by :: hint provided does not correspond to an existing index ``` [source]
- - [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) evaluates JavaScript and cannot take advantage of indexes. Therefore, query performance improves when you express your query using the standard MongoDB operators (e.g., [`$gt`](https://www.mongodb.com/docs/manual/reference/operator/query/gt.md#mongodb-query-op.-gt), [`$in`](https://www.mongodb.com/docs/manual/reference/operator/query/in.md#mongodb-query-op.-in)). [source]
- While there is no hard limit on the number of collections in a single MongoDB Atlas cluster, the performance of a cluster might degrade if it serves a large number of collections and indexes. Larger collections have a greater impact on performance. [source]
- If you cannot stop all writes to the collection during this procedure, do not use the procedure on this page. Instead, build your unique index on the collection by issuing [`db.collection.createIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#mongodb-method-db.collection.createIndex) on the primary for a replica set. [source]
- - You cannot create a hashed index on a field that contains an array *or* insert an array into a hashed indexed field. [source]
- - You cannot use hashed indexes in a compound index that becomes a multikey index. [source]
- You cannot specify a [unique constraint](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique) on a hashed index. Instead, you can create an additional non-hashed index with the unique constraint. MongoDB can use that non-hashed index to enforce uniqueness on the chosen field. [source]
- If the `$merge` attempts to write a document that violates any unique index on the output collection, the operation generates an error. For example: [source]
- - [Fail](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-whenMatched-fail) if there is a matching document in the collection. Specifically, the operation attempts to insert the matching document which violates the unique index on the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field(s). [source]
- | Metrics | Deployment metrics provide insight into hardware performance and database operation efficiency. Atlas collects metrics for your servers, databases, and MongoDB processes and stores metrics data at [various granularity levels](https://www.mongodb.com/docs/atlas/monitor-cluster-metrics/#premium-monitoring-granularity). For each granularity level, Atlas computes metrics as averages of the reported metrics at the next finer granularity level. Many metrics have a burst reporting equivalent. You can monitor metrics in the Atlas UI using the Metrics view, Real-Time Performance Panel, Quer [source]
- You cannot create [partial indexes](https://www.mongodb.com/docs/manual/core/index-partial.md#std-label-index-type-partial) on the metaField and timeField. [source]
- You cannot create sparse indexes on the metaField. [source]
- | **MongoDB Version** | **Changes** | | --- | --- | | 6.1 | Slow operation log messages include [cache refresh time fields.](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-cache-refresh-times) | | 6.2 | Slow operation log messages include a `queryFramework` field that indicates which query engine executed the query: `queryFramework: "classic"` indicates that the classic engine executed the query.; `queryFramework: "sbe"` indicates that the slot-based query execution engine executed the query. | | 6.3 | Slow operation log messages and [database profiler](ht [source]
- | Field | Type | Literal or Normalized | Description | | --- | --- | --- | --- | | `key` | Document | Literal | Contains the query shape and additional query attributes that group a set of queries together | | `key.queryShape` | Document | Literal | Contains attributes used to group similar queries together. For more information, see [Query Shape.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-queryShape) | | `key.client` | Document | Literal | Describes client information associated with the key | | `key.client.application` | Document | [source]
- The E number series are similar to the [Renard series](https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketauto.md#std-label-renard-series) in that they subdivide the interval from 1.0 to 10.0 by the 6 th, 12 th, 24 th, 48 th, 96 th, or 192 nd root of ten with a particular relative error. [source]
- The `$group` stage cannot include an accumulator expression with an empty field name. See [Empty Field Name $group Restriction](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-limit-Empty-Field-Name--group-Restriction) for details. [source]
- If the [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group) stage exceeds 100 megabytes of RAM, MongoDB writes data to temporary files. However, if the [allowDiskUse](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#std-label-aggregate-cmd-allowDiskUse) option is set to `false`, `$group` returns an error. For more information, refer to [aggregation pipeline limits.](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md#std-label-agg-pipeline-limits) [source]
- The [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/projection/elemmatch.md#mongodb-projection-proj.-elemMatch) projection operator takes an explicit condition argument. This allows you to project based on a condition not in the query, or if you need to project based on multiple fields in the array's embedded documents. See [Array Field Limitations](https://www.mongodb.com/docs/manual/reference/operator/projection/positional.md#std-label-array-field-limitation) for an example. [source]
- If the [`$graphLookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphlookup.md#mongodb-pipeline-pipe.-graphLookup) stage exceeds 100 megabytes of memory and the `allowDiskUse` option is set to `false`, [`$graphLookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphlookup.md#mongodb-pipeline-pipe.-graphLookup) returns an error. [source]
- Aggregation pipelines which call `$bottom` are subject to the [100 MB limit](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-limits.md#std-label-agg-memory-restrictions). If this limit is exceeded for an individual group, the aggregation fails with an error. [source]
- - You cannot specify a [`$text`](https://www.mongodb.com/docs/manual/reference/operator/query/text.md#mongodb-query-op.-text) query operator in an [`$elemMatch`.](https://www.mongodb.com/docs/manual/reference/operator/projection/elemmatch.md#mongodb-projection-proj.-elemMatch) [source]
- - You cannot use `$listSampledQueries` directly against a [`--shardsvr`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--shardsvr) replica set. When running on a sharded cluster, `$listSampledQueries` must run against a `mongos`. [source]
- As each stage in a `$facet` executes, the resulting document is limited to 100 megabytes. Note the [allowDiskUse](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#std-label-aggregate-cmd-allowDiskUse) flag doesn't affect the 100 megabyte size limit, since `$facet` can't spill to disk. [source]
- If a `$facet` stage constructs a document where the size exceeds the 100 megabyte limit, MongoDB returns an [`ExceededMemoryLimit`](https://www.mongodb.com/docs/manual/reference/error-codes.md#mongodb-error-146) error. [source]
- The final output document is subject to the 16 mebibyte [BSON document size limit](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-limit-BSON-Document-Size). If it exceeds 16 mebibytes, the aggregation produces an error. [source]
- Starting in MongoDB 8.3, the length of the string you provide to `chars` is limited to 4096 characters. If you provide a string longer than 4096 characters, MongoDB returns an error similar to the following: [source]
- - In general, you should use [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) only when you cannot express your query using another operator. If you must use [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where), try to include at least one other standard query operator to filter the result set. Using [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) alone requires a collection scan. [source]
- MongoDB Atlas uses the first 23 characters of a cluster's name. These characters must be unique within the cluster's project. Cluster names with fewer than 23 characters can't end with a hyphen (`-`). Cluster names with more than 23 characters can't have a hyphen as the 23rd character. [source]
- - MongoDB enforces additional restrictions with regards to projections. See [Projection Restrictions](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-limit-Projection-Restrictions) for details. [source]
- To avoid this error, if the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field does not include the `_id` field, remove the `_id` field in the aggregation results to avoid the error, such as with a preceding [`$unset`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset.md#mongodb-pipeline-pipe.-unset) stage, and so on. [source]
- If your collection uses [schema validation](https://www.mongodb.com/docs/manual/core/schema-validation.md#std-label-schema-validation-overview) and has `validationAction` set to `error`, inserting an invalid document or updating a document with invalid values with `$merge` throws a `MongoServerError` and the document is not written to the target collection. If there are multiple invalid documents, only the first invalid document encountered throws an error. All valid documents are written to the target collection, and all invalid documents fail to write. [source]
- Some high-latency [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) operations don't generate a slow query log for the foreign collection. This can occur because slow query logs correspond with operations that are reported in the [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler), whereas latency metrics increment only when a [collection lock](https://www.mongodb.com/docs/manual/faq/concurrency.md#std-label-faq-concurrency-locking) is acquired. [source]
- If the `$lookup` query on a shard can perform a local read, the `$lookup` doesn't record a separate operation for querying the foreign collection. A local read refers to when the query on the foreign collection targets only the same shard where the current operation is being executed. As a result, the `$lookup` operation increases the Namespace Insights latency metrics and operation counts, but does not generate a slow query log for the foreign collection. [source]
- Avoid increasing the WiredTiger internal cache size above its default value. If your case requires to do so, you can use `--wiredTigerCacheSizePct` to account for changes in memory due to vertical. You must specify a percentage of up to 80% of available memory. Calculated values can range from 0.256GB to 10000GB. For example, on a system with 2GB of RAM the `--wiredTigerCacheSizePct` cannot be set to 10 because 10% of 2GB is 0.2 GB, which is less than 0.256GB. [source]
- When running MongoDB servers and clients on NUMA hardware, you should configure a memory interleave policy so that the host behaves in a non-NUMA fashion. MongoDB checks NUMA settings on start up when deployed on Linux (since version 2.0) and Windows (since version 2.6) machines. If the NUMA configuration may degrade performance, MongoDB prints a warning. [source]
- When performing slow query analysis, the MCP Server retrieves a sample of slow queries, capped at 50 queries. The sample includes up to 50 most recent slow queries that match any specified conditions in your prompt to ensure optimal performance and response times. [source]
- You cannot use [`$function`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/function.md#mongodb-expression-exp.-function) as part of a [schema validation](https://www.mongodb.com/docs/manual/core/schema-validation/specify-query-expression-rules.md#std-label-schema-validation-query-expression) query predicate. [source]
- | Field | Type | Description | | --- | --- | --- | | `score` | Expression | Computes a new value from the input scores and stores the value in the [`$meta`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta.md#mongodb-expression-exp.-meta) keyword `score`. Returns an error for non-numeric inputs. | | `scoreDetails` | Boolean | Default is `false`. Specifies if `$score` computes and populates the `$scoreDetails` metadata field for each output document. See [scoreDetails](https://www.mongodb.com/docs/manual/reference/operator/aggregation/score.md#std-label-score-scoreDetails [source]
- Slow operation log messages include cache refresh time fields. [source]
- To determine if a merge operation or a shard issue is causing a slow query, compare the workingMillis and remoteOpWaitMillis time fields in the log. workingMillis is the total time the query took to complete. Specifically: [source]
- Starting in MongoDB 6.1, log messages for slow queries include the following cache refresh time fields: [source]
- You can only set a collection's `timeField` and `metaField` parameters when you create the collection. You cannot modify these parameters later. [source]
- For additional transactions usage considerations (such as runtime limit and oplog size limit), see also [Production Considerations.](https://www.mongodb.com/docs/manual/core/transactions-production-consideration.md#std-label-production-considerations) [source]
- For additional transactions usage considerations (such as runtime limit and oplog size limit), see also Production Considerations. [source]
- To optimize your query performance, [review the best practices for query performance](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#std-label-query-best-practices). You can also [analyze slow queries](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#std-label-analyze-slow-queries) and troubleshoot slow operations executed on your clusters. [source]
- The [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler) displays slow-running operations and their key performance statistics. You can explore a sample of historical queries for up to the last seven days without additional cost or performance overhead. Before you enable the Query Profiler, see [Considerations.](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-atlas-considerations-profile-database) [source]
Comparisons and alternatives
- Because data is indexed per bucket by metaField rather than one index entry per data point, MongoDB docs say time series indexes are much smaller than on regular collections, which improves WiredTiger in-memory cache use. [source]
- Starting in version 6.0, you can add a secondary index to any field in a time series collection. MongoDB indexes time series collections by [buckets](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucketing) of documents as opposed to individual documents. Time series buckets contain documents with shared metaField values, ordered by timeField values that are close together. MongoDB indexes the minimum and maximum values of all fields, except the metaField. Indexing buckets instead of individual documents reduces index size and improves query e [source]
- Compared to normal collections, storing time series data in time series collections improves query efficiency and reduces the disk usage for time series data and [secondary indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index). MongoDB 6.3 and later automatically creates a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on the time and metadata fields for new time series collections. [source]
- Since MongoDB 6.0 a secondary index can be added to any field of a time series collection. The server indexes buckets rather than individual documents, and stores the min and max of every field except the metaField, which reduces index size. [source]
- SERVER-79136: a $match followed by $group on the metaField with $min/$max was rewritten to use bucket-level control.min/control.max, ignoring the filter, so results were wrong (5 instead of 21 in the report). Affected 6.0.8 and 7.0.0-rc8; fixed in 5.0.20, 6.0.9, 7.0.0-rc9 and 7.1.0-rc0. [source]
- MongoDB reorders the `metaField` of time-series collections, which may cause servers to store data in a different field order than applications. If a `metaField` is an object, queries on the `metaField` may produce inconsistent results because `metaField` order may vary between servers and applications. To optimize queries on a time-series `metaField`, query the `metaField` on scalar sub-fields rather than the entire `metaField`. [source]
- | Counter | Description | | --- | --- | | `collscanNoFilter``collscanWithFilter` | Collection scan stages, counted separately based on whether the stage applies a filter. | | `ixscanNoFilter``ixscanWithFilter` | Index scan stages, counted separately based on whether the stage applies a filter. | | `fetchNoFilter``fetchWithFilter` | Fetch stages, counted separately based on whether the stage applies a filter. | | `andHashNoFilter``andHashWithFilter` | Hash-based index intersection stages, counted separately based on whether the stage applies a filter. | | `andSorted` | Sorted index intersection [source]
- To update the custom bucketing fields `bucketRoundingSeconds` and `bucketMaxSpanSeconds` instead of `granularity`, include both custom fields in the `collMod` command and set them to the same value: [source]
- MongoDB groups documents with matching `ticker` values. Instead of having to check for matches across all fields in all documents, the server only has to check against the `metaField`, in this case `ticker`, to narrow down the search range to a unique time series. This fits the expected use case, which is searching for activity on a single stock. A user searching for information on MongoDB stock (MDB) doesn't need to consider results for Amazon (AMZN). [source]
- For example, if you have two sensors that correspond to two `metaField` values, `sensor A` and `sensor B`, a batch that contains multiple measurements from a single sensor incurs the cost of one insert, rather than one insert per measurement. [source]
- Insert tip for many metaField values: batch documents with identical metaField together in insertMany with ordered:false, so one insert cost is paid per metaField value rather than per document. [source]
- Query tip: MongoDB reorders object metaField contents, so query scalar sub-fields (e.g. metaField.sensorId) rather than equality on the whole metaField object. Arrays as metaField may behave unexpectedly because array equality is order-dependent. The metaField field itself cannot be redefined after creation. [source]
- Indexes improve read performance, but a large number of indexes can negatively impact write performance since indexes must be updated during writes. If your collection already has several indexes, consider this tradeoff of read and write performance when deciding whether to create new indexes. Examine whether a query for such a collection can be modified to take advantage of existing indexes, as well as whether a query occurs often enough to justify the cost of a new index. [source]
- You can have a clustered index and add [secondary indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) to a clustered collection. Clustered indexes differ from secondary indexes: [source]
- Prior to MongoDB 6.0.7, if a [secondary index](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) existed on a clustered collection and the secondary index was usable by your query, the query planner selected the secondary index instead of the clustered index by default. In MongoDB 6.1 and prior, to use the clustered index, you must provide a hint because the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) does not automatically select the clustered index. [source]
- - To avoid network roundtrips, use a single [`insertMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertmany.md#mongodb-method-db.collection.insertMany) statement as opposed to multiple [`insertOne()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertone.md#mongodb-method-db.collection.insertOne) statements. [source]
- Applications may target different members of a replica set. As such, each replica set member might receive different read commands and have plan cache information that differs from other members. Nevertheless, running `$planCacheStats` on a replica set or a sharded cluster obeys the normal read preference rules. That is, on a replica set, the operation gathers plan cache information from just one member of replica set, and on a sharded cluster, the operation gathers plan cache information from just one member of each shard replica set. [source]
- | Condition | Recommended Alert Threshold: Low Priority | Recommended Alert Threshold: High Priority | Key Insights | | --- | --- | --- | --- | | Oplog Window | < 24h for 5 minutes | < 1h for 10 minutes | Monitor the replication oplog window, together with replication headroom, to determine whether the secondary may soon require a full resync. The replication oplog window often helps to determine in advance the resilience of secondaries to planned and unplanned outages. | | [Election](https://www.mongodb.com/docs/manual/core/replica-set-elections/) events | > 3 for an hour, notify after 5 minu [source]
- In MongoDB 6.3 and later, instead of `granularity`, you can set bucket boundaries manually using the two custom bucketing parameters. Consider this approach if you expect to query data for fixed time intervals, such as every 4 hours starting at midnight. Ensuring buckets don't overlap between those periods optimizes for high query volume and [`insert`](https://www.mongodb.com/docs/manual/reference/command/insert.md#mongodb-dbcommand-dbcmd.insert) operations. [source]
- For the weather station example, if you generate summary reports every 4 hours, you could adjust bucketing by setting the custom bucketing parameters to 14400 seconds instead of using a `granularity` of `"minutes"`: [source]
Facts and statements
- The following command creates a compound secondary index on `metaField` (ascending) and `timeField` (descending): [source]
- The following last point query example uses the descending `timeField` compound secondary index created above: [source]
- Last-point queries (latest reading per metaField value) are served by compound indexes on the metaField and timeField in any direction. They are fastest with the DISTINCT_SCAN optimization, which needs a descending timeField index, for example {metadata.sensorId: 1, timestamp: -1}. [source]
- SERVER-63279: pushing a metaField predicate past a stage that changes document contents (for example $project) returned wrong results. Affected 5.0.5 and 5.2.0; fixed in 5.0.7, 5.2.2 and 5.3.0. After the fix, a $match placed after a document-reshaping stage may stay after the unpack and cost more. [source]
- SERVER-96923, a bounded sort optimization for time series queries that do not sort on timeField, is an unresolved backlog feature request (last updated 2026-09-25), so such sorts are not guaranteed to be bounded. [source]
- In time series data, a last point query returns the data point with the latest timestamp for a given field. For time series collections, a last point query fetches the latest measurement for each unique metadata value. For example, you may want to get the latest temperature reading from all sensors. Improve performance on last point queries by creating any of the following indexes: [source]
- If the `queryPlanner.winningPlan.inputStage.stage` is either `CLUSTERED_IXSCAN` or `IXSCAN`, the index was used. For more information on the explain plan output, see [Explain Results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) [source]
- The `winningPlan.queryPlan.inputStage.stage` is `DISTINCT_SCAN`, which indicates that the index was used. For more information on the explain plan output, see [Explain Results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) [source]
- - You can only create [multikey indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey.md#std-label-index-type-multikey) on the `metaField`. [source]
- - You can only create [2d indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2d.md#std-label-2d-index) on the `metaField`. [source]
- - You can only create [sparse indexes](https://www.mongodb.com/docs/manual/core/index-sparse.md#std-label-index-type-sparse) on the `metaField`. [source]
- The default compound index covers the whole metaField subdocument, so it is only used for $eq on the metaField. To serve other predicates such as $in, create a secondary index on specific metaField subfields, for example metadata.type. [source]
- Guidance on field roles: use the metaField index for filtering and equality, and use the timeField and other indexed fields for range queries. If timeField values fall before 1970-01-01 or after 2038-01-19, create an index on the timeField to keep queries fast. [source]
- A forum workaround sorts system.buckets.<name> on control.max.timestamp and then looks up the document in the view. One reader reported that control.max.timestamp did not return the true latest record in their data, so the workaround can be wrong with out-of-order ingest. [source]
- The optimizer pushes $match predicates past $_internalUnpackBucket: predicates on the metaField push down exactly, $lt on a measurement becomes $lt on control.min in the bucket predicate, and $geoWithin becomes $_internalBucketGeoWithin. The same logic is reused to translate partial index filters into bucket-level filters. [source]
- Put metaField and time-range $match stages first in the pipeline, and index the metaField (and time) fields. A leading $match on indexed meta fields restricts the buckets that get unpacked; a compound index on meta subfields supports a $match then $group pattern in place of distinct(). [source]
- For more information and examples, see [Add Secondary Indexes to Time Series Collections.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) [source]
- Sort operations on time series collections can use secondary indexes on the `timeField` field. Under certain conditions, sort operations can also use compound secondary indexes on the `metaField` and `timeField` fields. [source]
- Time series collections support [secondary indexes](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) on the field specified as the `metaField`. If the data model of your time series data does not have a designated field for your metadata, you can transform your data to create one. To transform the data in your existing collection, use [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) to create a temporary collection with your time series data. [source]
- Using the `metaField` to shard your collection provides sufficienct cardinality as a shard key for time series collections. [source]
- Starting in MongoDB 6.3: if you create a new time series collection, MongoDB also generates a compound index on the metaField and timeField fields. To improve query performance, queries on time series collections use the new compound index. The compound index also uses the optimized storage format. [source]
- 2dsphere indexes can be created on the timeField, metaField or measurement fields since 6.0, per the secondary index page. The OneUptime blog says they are supported only on metaField subfields. Time series collections support only $geoNear for sorting by distance; $near and $nearSphere do not work. [source]
- SERVER-100910: for compound time series indexes the planner's sortMatchesTraversalPreference always returned false, so reversed-direction (backward scan) plans were not generated and sorts could miss the bounded sort optimization. Closed Fixed in 9.0.0-rc0 on 2026-05-14; earlier versions are affected. [source]
- Not all index types are supported. For a list of unsupported index types, see [Limitations for Secondary Indexes on Time Series Collections.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#std-label-timeseries-limitations-secondary-indexes) [source]
- Block processing applies to aggregation pipelines that begin with $match, with $sort on the timeField only, or with $group. A MongoDB blog also names $setWindowFields as an analytical stage that benefits, but gives no complete list of supported operators. [source]
- Each bucket stores control.min and control.max for the time field and measurements, which lets range queries skip buckets that fall entirely outside the query range before unpacking. [source]
- The number of buckets in a time series collection depends on the number of unique `metaField` values. Collections with fine-grained or dynamic `metaField` values may generate more, sparsely packed, short-lived buckets than collections with simple `metaField` values that rarely or never change. Fine-grained and dynamic `metaField` values typically decrease storage and query effiency. [source]
- Starting in MongoDB 6.3, you can use the custom bucketing parameters `bucketMaxSpanSeconds` and `bucketRoundingSeconds` to specify bucket boundaries and more precisely control how time series data is bucketed. [source]
- Choosing the right `metaField` for your collection optimizes both storage and query performance. For more information on `metaField` selection and best practices, see [metaFields.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-timeseries-collections-metafield) [source]
- For more detailed information on selecting a `granularity` value, see [Granularity Considerations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-considerations.md#std-label-timeseries-granularity-considerations) [source]
- For more information on modifying time series intervals, see [Change Time Series Granularity.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-change-granularity) [source]
- You query a time series collection the same way you query a standard MongoDB collection. For an example query and example aggregation pipeline, see [Query a Time Series Collection](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#std-label-timeseries-query-example). For a list of querying best practices, see [Query Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-query-performance) [source]
- Granularity mismatch inflates bucket count or traversal cost: granularity 'hours' for 5-minute data puts up to a month of events in one bucket (slower queries); 'seconds' creates many single-document buckets. Granularity or bucketing span can later be increased but not decreased. [source]
- If an [embedded data model](https://www.mongodb.com/docs/manual/data-modeling/embedding.md#std-label-data-modeling-embedding) supports your application's needs, use nested fields. The behavior of nested fields does not differ between regular collections and time series collections. [source]
- Compression best practices (omit empty fields, round numerics, keep consistent field order) reduce on-disk bucket size; schema changes between documents leave following documents uncompressed. [source]
- ```javascript sh.shardCollection( "test.weather", { "metadata.sensorId": 1 }, { timeseries: { timeField: "timestamp", metaField: "metadata", granularity: "hours" } } ) ``` [source]
- - Specifies a `granularity` of hours. [source]
- Choosing the right field as your time series `metaField` and `grandularity` optimizes both storage and query performance. For more information on field selection and best practices, see [metaField and Granularity Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-query-performance) [source]
- The aggregation pipeline uses the [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) and [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) stages to determine which indexes a time series collection can use. An index can be used in the following scenarios: [source]
- On a time series collection, you can specify hints using either the index name or the index key pattern. To get the names of the indexes on a collection, use the [`db.collection.getIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getindexes.md#mongodb-method-db.collection.getIndexes) method. [source]
- The aggregation pipeline stages [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) and [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) determine which indexes a time series collection can use. An index can be used in the following scenarios: [source]
- On a time series collection, you can specify hints using either the index name or the index key pattern. To get the names of the indexes on a collection, use `GetIndexes()`. [source]
- For operations on time series collections, the filter used to reduce the number of buckets queried in the bucket catalog. [source]
- For operations on time series collections, the filter used to query the bucket catalog. [source]
- Compression requires consistent nested field order. For more information on compression with nested fields, see [Nested Fields Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-embedded-fields) [source]
- * You can create [partial](https://www.mongodb.com/docs/manual/core/index-partial.md#std-label-index-type-partial) and [2dsphere](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2dsphere.md#std-label-2dsphere-index) indexes on any field in a [time series collection.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) [source]
- The Performance Advisor doesn't provide performance suggestions for time series collections. [source]
- - General indexing strategies also apply to time series collections. For more information, see [Indexing Strategies.](https://www.mongodb.com/docs/manual/applications/indexes.md#std-label-indexing-strategies) [source]
- - A sort on `{ <metaField>: ±1, timeField: ±1 }` uses the default compound index on `{ <metaField>: ±1, timeField: ±1 }`. [source]
- Starting in version 6.0 you can create 2dsphere indexes on the `timeField`, `metaField`, or measurement fields. For example, the following operation creates a 2dsphere index on the `location` field: [source]
- - Sort on `{ <metaField>: ±1, timeField: ±1 }` uses the default [source]
- compound index on `{ <metaField>: ±1, timeField: ±1 }` [source]
- Starting in version 6.0, you can create 2dsphere indexes on the `timeField`, `metaField`, or measurement fields. For example, the following operation creates a 2dsphere index on the `location` field: [source]
- Starting in MongoDB 7.0, you can create partial TTL indexes on [time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing). These indexes use the collection `timeField` as the key field, and require a [partial filter expression](https://www.mongodb.com/docs/manual/core/index-partial.md#std-label-index-type-partial) on the `metaField`. [source]
- Time series collections include an optional `expireAfterSeconds` field. If you don't set `expireAfterSeconds`, a TTL index with a `partialFilterExpression` lets you set an expiration period for documents that match the filter. If you do set `expireAfterSeconds`, a partial TTL index lets you set a different, shorter expiration period for matching documents. You can only create a `partialFilterExpression` on the `metaField`. [source]
- - Starting in MongoDB 7.0, you can create a [partial TTL index](https://www.mongodb.com/docs/manual/core/index-partial.md#std-label-partial-ttl-indexes) on a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing)'s `metaField`. In earlier MongoDB versions, you can only create a TTL index for a time series collection's `timeField`. [source]
- If there are [secondary indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) on [time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) and you need to downgrade the feature compatibility version (FCV), you must first drop any secondary indexes that are incompatible with the downgraded FCV. For more information, see [`setFeatureCompatibilityVersion`.](https://www.mongodb.com/docs/manual/reference/command/setfeaturecompatibilityversion.md#mongodb-dbcommand-dbcmd.setFeatureCompati [source]
- Compare this to a time series collection. Time series collections write data in order, meaning recent transactions can be kept in memory for much faster retrieval. Since they are written in sequence, documents are stored together, so there's no need to read every disk block after a document is no longer in memory. Data is indexed by the `metaField`, leading to much smaller indexes. [source]
- MongoDB automatically creates a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on both the metaField and timeField of a time series collection. [source]
- Before downgrading the feature compatibility version, drop every time series secondary index that the lower FCV does not support. Otherwise the downgrade is blocked. [source]
- - Use the metaField index for filtering and equality. [source]
- - Use the timeField and other indexed fields for range queries. [source]
- - The clustered index key must be `{ _id: 1 }`. [source]
- Indexes on time series collections generally behave like indexes on regular collections, but with several additional considerations and limitations. [source]
- This example uses the [`$densify`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#mongodb-pipeline-pipe.-densify) stage to fill in the gaps between the four-hour intervals to achieve hourly granularity for the data points: [source]
- ```csharp var timeSeriesOptions = new TimeSeriesOptions( timeField: "date", metaField: "ticker", bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600 ); [source]
- You can either use **manual bucketing** by defining a `granularity` field or **interval bucketing** by defining both `bucketMaxSpanSeconds` and `bucketRoundingSeconds` fields: [source]
- - Define a `granularity` field, as shown above. [source]
- - In MongoDB 6.3 and later, you can define `bucketMaxSpanSeconds` and `bucketRoundingSeconds` fields. [source]
- After creation, you can modify granularity or bucket definitions by using the .NET/C# driver `RunCommand()` method to run the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) database command. However, you can only increase the time span covered by each bucket. [source]
- ```java TimeSeriesOptions timeSeriesOptions = new TimeSeriesOptions("time") .metaField("sensor") .granularity(TimeSeriesGranularity.HOURS); // '.SECONDS' | '.MINUTES' | '.HOURS' [source]
- Define the `timeField` and `metaField`. [source]
- You can either use **manual bucketing** by defining a `granularity` field or **interval bucketing** by defining both the `bucketMaxSpan` and `bucketRounding` fields: [source]
- ```java TimeSeriesOptions timeSeriesOptions = new TimeSeriesOptions("time") .metaField("sensor") .bucketMaxSpan( (long) 3600, TimeUnit.SECONDS) .bucketRounding( (long) 3600, TimeUnit.SECONDS); [source]
- After creation, you can modify granularity or bucket definitions by using the Java Driver `runCommand()` method to run the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) database command. However, you can only increase the time span covered by each bucket. [source]
- ```javascript const settings = { timeseries: { timeField: 'time', metaField: 'sensor', bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600, }, expireAfterSeconds: 86400, // optional }; [source]
- After creation, you can modify granularity or bucket definitions by using the Node.js Driver `command()` method to run the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) database command. However, you can only increase the time span covered by each bucket. [source]
- ```python time_series_options = { "timeField": "time", "metaField": "sensor", "granularity": "hours", } expire_after_seconds = 86400 # optional [source]
- You can either use **manual bucketing** by defining a `granularity` field or **interval bucketing** by defining both the `bucketMaxSpanSeconds` and `bucketRoundingSeconds` fields: [source]
- - As an alternative to `granularity`, you can define the `bucketMaxSpanSeconds` and `bucketRoundingSeconds` fields. [source]
- ```python time_series_options = { "timeField": "time", "metaField": "sensor", "bucketMaxSpanSeconds": 3600, "bucketRoundingSeconds": 3600 } expire_after_seconds = 86400 # optional [source]
- After creation, you can modify granularity or bucket definitions by using the PyMongo Driver `command()` method to run the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) database command. However, you can only increase the time span covered by each bucket. [source]
- After creation, you can modify granularity or bucket definitions by using the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) database command. However, you can only increase the time span covered by each bucket. [source]
- Queries against time series data typically focus on a single time series in the collection. For example, consider a time series collection that tracks stock data using the following schema: [source]
- By default, WiredTiger uses Snappy block compression for all collections and prefix compression for all indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation. [source]
- - Indexes loaded in the WiredTiger internal cache have a different data representation to the on-disk format, but can still take advantage of index prefix compression to reduce RAM usage. Index prefix compression deduplicates common prefixes from indexed fields. [source]
- ```javascript db.createCollection( "deliverySensor", { timeseries: { timeField: "timestamp", metaField: "metadata", granularity: "minutes" } } ) ``` [source]
- - Specifies the `metadata.location` field as the [shard key](https://www.mongodb.com/docs/manual/core/sharding-shard-key.md#std-label-shard-key). `location` is a sub-field of the collection's `metaField`. [source]
- - A sort on `{ <timeField>: ±1 }` uses a secondary index on `<timeField>`. [source]
- - Sort on `{ <timeField>: ±1 }` uses a secondary index on [source]
- For more information on time series queries, see [Query Best Practices.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-tsc-best-practice-optimize-query-performance) [source]
- For more information on aggregations, see [Aggregation and Operator Considerations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#std-label-manual-timeseries-aggregations-operators) [source]
- If you use MongoDB 7.0 or greater and already have your data in a MongoDB database, migrate with an [aggregation pipeline.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#std-label-migrate-data-into-a-timeseries-collection-with-aggregation) [source]
- If your data is in a relational database, use [Relational Migrator](https://www.mongodb.com/docs/relational-migrator/mapping-rules/mapping-rule-options/time-series/) to migrate your data into a time series collection. [source]
- - The Namespace Insights tab doesn't support [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections/) [source]
- - If you use a clustered index as a TTL index, it improves document delete performance and reduces the clustered collection storage size. [source]
- - Large keys increase the storage size of the clustered collection and its secondary indexes which decreases clustered collection performance. [source]
- Internally, MongoDB optimizes time series data by grouping documents in a time series collection based on common `metaField` values. Selecting a useful one provides significant optimizations to storage density and query performance. For more information, see [metaFields.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-timeseries-collections-metafield) [source]
- - An identical `metaField` value, which should uniquely identify a time series. If a `metaField` is an object or array, MongoDB groups only if all object fields or array elements match. [source]
- - `timeField` values that are close together. The time series collection's `granularity`, `bucketMaxSpanSeconds`, and `bucketRoundingSeconds` parameters control the time span covered by each bucket. For more information, see [Set Granularity for Time Series Data.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity) [source]
- You can modify a time series collection's granularity, but only to change from finer to coarser measurements, such as extending bucket coverage from minutes to hours. This doesn't change how data is stored across existing buckets. [source]
- The starting timestamp of a new bucket is rounded down based on the collection's [granularity](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity). This handles cases where documents with out-of-order timestamps arrive in close succession. [source]
- - Time has moved forward or backward past the covered time span, as indicated by an incoming document timestamp that falls outside of the bucket's bounds. These bounds are determined by the collection's [granularity](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity) setting. [source]
- Common queries for time series data are querying the `metaField` to get data for a single time series, or using a range query on the `timeField` to get data for a given time span. [source]
- ```java // Specify the time series options to configure the collection TimeSeriesOptions timeSeriesOptions = new TimeSeriesOptions("date") .metaField("ticker") .granularity(TimeSeriesGranularity.SECONDS); [source]
- ```javascript timeseries: { timeField: "date", metaField: "ticker", granularity: "seconds" } ``` [source]
- ```bash db.createCollection( "stocks", { timeseries: { timeField: "date", metaField: "ticker", granularity: "seconds" } }) ``` [source]
- ```javascript const options = { timeseries: { timeField: 'date', metaField: 'ticker', granularity: 'seconds', }, }; [source]
- - To learn about custom bucketing parameters in MongoDB 6.3 and later, see [Using Custom Bucketing Parameters.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-flexible-bucketing) [source]
- If your collection doesn't include a field you can use to identify each series, transform your data to define one. In this example, we create a `metaData` field that will be used for the `metaField` property of the time series collection we will later create. [source]
- The `timeField` of a time series collection must be a [date](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-document-bson-type-date) type. [source]
- If your collection doesn't include a field you can use to identify each series, transform your data to define one. In this example, the `metaData` field becomes the `metaField` of the time series collection that you create. [source]
- ```java out(new Document("db", "mydatabase") .append("coll", "weather_new") .append("timeseries", new Document("timeField", "ts") .append("metaField", "metaData") .append("granularity", "seconds"))) [source]
- ```java List<Bson> pipeline = Arrays.asList( addFields( new Field<>("metaData", new Document("st", "$st") .append("position", "$position") .append("elevation", "$elevation") .append("callLetters", "$callLetters") .append("qualityControlProcess", "$qualityControlProcess") .append("type", "$type"))), project(fields( include("_id", "ts", "metaData", "dataSource", "airTemperature", "dewPoint", "pressure", "wind", "visibility", "skyCondition", "sections", "precipitationEstimatedObservation"))), out(new Document("db", "mydatabase") .append("coll", "weather_new") .append("timeseries", new Document("t [source]
- ```javascript { $out: { db: "mydatabase", coll: "weather_new", timeseries: { timeField: "ts", metaField: "metaData", granularity: "seconds" } } } [source]
- ```javascript db.weather_data.aggregate([ { $addFields: { metaData: { "st": "$st", "position": "$position", "elevation": "$elevation", "callLetters": "$callLetters", "qualityControlProcess": "$qualityControlProcess", "type": "$type" } }, }, { $project: { _id: 1, ts: 1, metaData: 1, dataSource: 1, airTemperature: 1, dewPoint: 1, pressure: 1, wind: 1, visibility: 1, skyCondition: 1, sections: 1, precipitationEstimatedObservation: 1 } }, { $out: { db: "mydatabase", coll: "weather_new", timeseries: { timeField: "ts", metaField: "metaData", granularity: "seconds" } } } ]) [source]
- ```javascript { $out: { db: 'mydatabase', coll: 'weather_new', timeseries: { timeField: 'ts', metaField: 'metaData', granularity: 'seconds', }, }, }, [source]
- const pipeline = [ { $addFields: { metaData: { st: '$st', position: '$position', elevation: '$elevation', callLetters: '$callLetters', qualityControlProcess: '$qualityControlProcess', type: '$type', }, }, }, { $project: { _id: 1, ts: 1, metaData: 1, dataSource: 1, airTemperature: 1, dewPoint: 1, pressure: 1, wind: 1, visibility: 1, skyCondition: 1, sections: 1, precipitationEstimatedObservation: 1, }, }, { $out: { db: 'mydatabase', coll: 'weather_new', timeseries: { timeField: 'ts', metaField: 'metaData', granularity: 'seconds', }, }, }, ]; [source]
- ```python { "$out": { "db": "mydatabase", "coll": "weather_new", "timeseries": { "timeField": "ts", "metaField": "metaData", "granularity": "seconds" } } } [source]
- ```python pipeline = [ { "$addFields": { "metaData": { "st": "$st", "position": "$position", "elevation": "$elevation", "callLetters": "$callLetters", "qualityControlProcess": "$qualityControlProcess", "type": "$type" } } }, { "$project": { "_id": 1, "ts": 1, "metaData": 1, "dataSource": 1, "airTemperature": 1, "dewPoint": 1, "pressure": 1, "wind": 1, "visibility": 1, "skyCondition": 1, "sections": 1, "precipitationEstimatedObservation": 1 } }, { "$out": { "db": "mydatabase", "coll": "weather_new", "timeseries": { "timeField": "ts", "metaField": "metaData", "granularity": "seconds" } } } ] [source]
- **Important: Changing Time Series Granularity** [source]
- This example uses sample data for the `timeField`, `metaField`, and `granularity`. For more information on the preceeding command, see [Create a Time Series Collection.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#std-label-manual-timeseries-collection-create) [source]
- MongoDB doesn't guarantee that expired data will be deleted immediately upon expiration. Once all documents in a bucket are expired, the background task that removes expired buckets removes the bucket during the next run. The maximum span of time that a single bucket is allowed to cover is controlled by the `granularity` of the time series collection: [source]
- Stages that unpack time series buckets. [source]
- For more information on bucketing, see [About Time Series Data.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucketing) [source]
- You can increase `timeseries.granularity` from a shorter unit of time to a longer one using a [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command. [source]
- The second major dimension for querying time series data is time. Since MongoDB groups documents that have both an identical `metaField` value and close `timeField` values, this further narrows the scope of a query to a range of buckets. Recent transactions are kept in memory, so it's easy to stream data in real time. [source]
- Read operations on time series collections with read concern `"snapshot"` guarantee snapshot isolation only in the absence of concurrent drop or rename operations on collections in the read operation. Re-creating a time series collection on the same namespace with different granularity setting does not yield full snapshot isolation. [source]
- Your choice of `metaField` has the biggest impact on optimizing queries in your application. [source]
- You can improve performance by setting the `granularity` or custom bucketing parameters to the best match for the time span between incoming measurements from the same data source. For example, if you are recording weather data from thousands of sensors but only record data from each sensor once per 5 minutes, you can either set `granularity` to `"minutes"` or set the custom bucketing parameters to `300` (seconds). [source]
- Once you set a collection's `granularity` or the custom bucketing parameters `bucketMaxSpanSeconds` and `bucketRoundingSeconds`, you can increase the time span covered by a bucket, but not decrease it. Use the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command to modify the parameters. [source]
- Fine-grained or changing metaField values generate many sparsely packed, short-lived buckets, increasing collection cardinality and decreasing storage and query efficiency (official docs; no numeric threshold given). [source]
- Docs' metaField rules: choose fields that rarely or never change; prefer stable identifiers common in filters; do not put fields not used for filtering in the metaField, store them as measurements. The docs say the metaField choice has the biggest impact on query optimization. [source]
- Scoping: docs state the compressed bucket format in cache 'supports high cardinality workloads while preserving efficient query performance', so high cardinality is not prohibited; the penalty applies mainly to sparse/short-lived buckets from fine-grained or changing values. [source]
- Time series collections are optimized for time data, so performance depends heavily on how you configure them at creation. For more information, see [Time Series Collection Considerations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-considerations.md#std-label-manual-timeseries-considerations) [source]
- - For aggregation and query behaviors specific to time series collections, see [Aggregation and Operator Considerations.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#std-label-manual-timeseries-aggregations-operators) [source]
- For more information on additional considerations for migrating your data, see [Best Practices for Time Series Collections.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#std-label-timeseries-best-practices) [source]
- This page describes best practices to improve performance and data usage for time series collections. [source]
- [Time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) generally behave like regular collections with several limitations. [source]
- Time series collections are subject to several sharding limitations. [source]
- Best Practices for Time Series Collections [source]
- Before completing this tutorial, review the [sharding limitations](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#std-label-time-series-limitations-sharding) for time series collections. [source]
- Round numeric data to the precision that your application requires. Rounding numeric data to fewer decimal places improves the compression ratio. [source]
- MongoDB uses column compression on each nested field individually, which provides the same compression quality as flattening the fields to the top level. The resulting compression is identical to the compression that would result from flattening all of the nested fields to top level fields. [source]
- Column compression requires a consistent nested field order. However, if you use a driver to interact with your data, there may be additional ordering considerations. For example, see [BSON Types](https://www.mongodb.com/docs/drivers/go/current/data-formats/bson/) for ordered representation considerations for the Go driver. Refer to [driver documentation](https://www.mongodb.com/docs/drivers/) for more information. [source]
- Using a consistent field order in your documents improves insert and compression performance. [source]
- With the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes. [source]
- - Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server. [source]
- For more information, see metaField Considerations. [source]
- The default compound index for the collection indexes the entire `metadata` subdocument, so the index is only used with [`$eq`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq.md#mongodb-expression-exp.-eq) queries. By indexing specific `metadata` fields, you improve query performance for other query types. [source]
- Starting in version 6.0 you can create `2dsphere` indexes. For example, the following operation creates a 2dsphere index on the `location` field: [source]
- - Set your index keys to be as small in size as possible. [source]
- If you use the `_id` field in a range query, performance is improved. For example, the following query uses `_id` and [`$gt`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt.md#mongodb-expression-exp.-gt) to return the orders where the order date is greater than the supplied date: [source]
- Compression requires consistent nested field order. For more information on compression with nested fields, see Nested Fields Best Practices. [source]
- If you have more than one geospatial index on the collection, use the `keys` parameter to specify which field to use in the calculation. If you have only one geospatial index, `$geoNear` implicitly uses the indexed field for the calculation. [source]
- Log analysis rate limits apply only to the Performance Advisor UI, the Query Insights UI, and the Access Tracking UI. [Downloadable log files](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-downloadgroupclusterlog) are always complete. [source]
- The Performance Advisor includes a user feedback button for Index Suggestions on dedicated clusters. [source]
- - You can only create one index at a time through the Performance Advisor. If you want to create more simultaneously, you can do so using the [Atlas UI](https://www.mongodb.com/docs/atlas/atlas-ui/indexes.md#std-label-atlas-ui-indexes), a [driver](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver), or the [shell](https://www.mongodb.com/docs/atlas/mongo-shell-connection.md#std-label-connect-mongo-shell) [source]
- - Atlas always creates indexes for entire clusters. If you create an index while viewing the Performance Advisor for a single shard in a sharded cluster, Atlas creates that index for the entire sharded cluster. [source]
- 1. Creating a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on `meta.project` and `meta.type` and supports the aggregation. [source]
- Rolling index builds lower the resiliency of your cluster and increase build duration. [source]
- - Wildcard indexes omit the `_id` field by default. To include the `_id` field in a wildcard index, you must explicitly include it in the `wildcardProjection` document. [source]
- - You can create more than one wildcard index on a collection. [source]
- - A wildcard index may cover the same fields as other indexes in the collection. [source]
- - Compound wildcard indexes are sparse indexes. [source]
- - Documents are included in the index if they are missing the wildcard field but have one of the compound fields. [source]
- - Index fields, including wildcard fields, can be sorted in ascending (`1`) or descending (`-1`) order. [source]
- MongoDB disallows the creation of version 0 indexes. [source]
- In previous versions, MongoDB did not create the index again, but would return a response object with `ok` value of `1` and a note that implied that the index was not recreated. For example: [source]
- Each [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) in the replica set or sharded cluster *must* have [featureCompatibilityVersion](https://www.mongodb.com/docs/manual/reference/command/setfeaturecompatibilityversion.md#std-label-set-fcv) set to at least `4.4` to start index builds simultaneously across replica set members. [source]
- Index builds on a replica set or sharded cluster build simultaneously across all data-bearing replica set members. For sharded clusters, the index build occurs only on shards containing data for the collection being indexed. The primary requires a minimum number of data-bearing [`voting`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.votes) members (i.e commit quorum), including itself, that must complete the build before marking the index as ready for use. See [Index Builds in Replicated Environments](https://www.mongodb.com/docs/manua [source]
- The following indexes only support simple binary comparison and do not support [collation:](https://www.mongodb.com/docs/manual/reference/collation.md#std-label-collation) [source]
- - [Text](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-type-text) indexes are not available in Stable API V1. [source]
- - Statistics for an index reset on [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) restart or index drop and recreation. [source]
- - Modification of an existing index (see [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-collflag-index) command) resets the statistics for that index. [source]
- - Create queries that your current indexes support to reduce the time needed to search for your results. [source]
- - Avoid creating documents with large array fields that require a lot of processing to search and index. [source]
- - Optimize your indexes and remove unused or inefficient indexes. Too many indexes can negatively impact write performance. [source]
- - Consider the suggested indexes from the [Performance Advisor](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-performance-advisor) with the highest Impact scores and lowest Average Query Targeting scores. [source]
- - Perform [rolling index builds](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-replica-sets/#rolling-index-builds-on-replica-sets) to reduce the performance impact of building indexes on [replica sets](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) and [sharded clusters.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-sharded-cluster) [source]
- - [Drop unused, redundant, and hidden indexes](https://www.mongodb.com/docs/atlas/performance-advisor/drop-indexes.md#std-label-pa-drop-index) to improve write performance and free storage space. [source]
- - The non-[`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) query statements may use an [index.](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-collflag-index) [source]
- | MongoDB Atlas Cluster Tier | Recommended Maximum | | --- | --- | | `M10` | 5,000 collections and indexes | | `M20` / `M30` | 10,000 collections and indexes | | `M40`/+ | 100,000 collections and indexes | [source]
- A [shard key](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-shard-key) index can be an ascending index on the shard key, a compound index that starts with the shard key and specifies ascending order for the shard key, or a [hashed index.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md#std-label-index-type-hashed) [source]
- [Hashed shard keys](https://www.mongodb.com/docs/manual/core/hashed-sharding.md#std-label-sharding-hashed-sharding) and [hashed indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md#std-label-index-type-hashed) store hashes of keys with ascending values. [source]
- By default, you can have up to three concurrent index builds. To learn more, see [Maximum Concurrent Index Builds.](https://www.mongodb.com/docs/manual/core/index-creation/#maximum-concurrent-index-builds) [source]
- The hashing function does not support [multikey indexes:](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey.md#std-label-index-type-multikey) [source]
- Not all [index types](https://www.mongodb.com/docs/manual/core/indexes/index-types.md#std-label-index-types) can cover queries. For details on covered index support, refer to the documentation page for the corresponding index type. [source]
- - Do not create indexes on encrypted fields. Creating indexes on encrypted fields that use Queryable Encryption negatively affect performance. Instead, you can create an index on the `__safeContent__` field to support queries on encrypted fields. [source]
- If the output collection does not exist, `$merge` requires the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) identifier to be the `_id` field. To use a different `on` field value for a collection that does not exist, you can create the collection first by creating a unique index on the desired field(s) first. For example, if the output collection `newDailyCommentCount` does not exist and you want to specify the `commentDate` field as the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) id [source]
- With the sharded collection `moviesByYearAndRating` and the unique index created, you can use `$merge` to output the aggregation results to this collection, matching on `[ "year", "rated" ]` as in this example: [source]
- If the unique index used by `$merge` for [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field(s) is dropped mid-aggregation, there is no guarantee that the aggregation will be killed. If the aggregation continues, there is no guarantee that documents do not have duplicate `on` field values. [source]
- - [Insert a non-matching document](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-whenNotMatched-insert) that violates a unique index other than the index on the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field(s). [source]
- - [Replace an existing document](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-whenMatched-replace) with a new document that violates a unique index other than the index on the [on](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#std-label-merge-on) field(s). [source]
- - If `$in` has fewer than 201 array elements, the elements are expanded and then merged in the sort order specified for the index using a `SORT_MERGE` stage. This improves performance for small arrays. In this case, `$in` is similar to an equality predicate with ESR. [source]
- - If `$in` has 201 elements or more, the elements are ordered like a range operator. In this case, the performance improvement for small arrays isn't realized. It isn't possible for the subsequent fields in the index to be used for sorting, and `$in` is similar to a range predicate with ESR. [source]
- - If you typically use `$in` operators with small arrays, include them earlier in the index specification. If you typically use large arrays, include `$in` operators where you would include a range predicate. [source]
- - `metadata`: The estimate comes from database metadata like collection cardinality. [source]
- For the WiredTiger storage engine, you can also store the indexes on a different storage device. See [`storage.wiredTiger.engineConfig.directoryForIndexes`.](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-storage.wiredTiger.engineConfig.directoryForIndexes) [source]
- For general performance strategies, see [Indexing Strategies](https://www.mongodb.com/docs/manual/applications/indexes.md#std-label-manual-indexing-strategies) and [Query Optimization.](https://www.mongodb.com/docs/manual/core/query-optimization.md#std-label-read-operations-indexing) [source]
- For example, this [`$in`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in.md#mongodb-expression-exp.-in) query benefits from a secondary index on `metadata.type`: [source]
- The following sort operation on the `timestamp` field uses the Secondary Index to improve performance: [source]
- If your original collection had secondary indexes, manually recreate them now. [source]
- Clustered collections are created with a [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex). The clustered index specifies the order in which documents are stored. [source]
- - Faster queries on clustered collections without needing a secondary index, such as queries with range scans and equality comparisons on the clustered index key. [source]
- - A clustered index is also a TTL index if you specify the [expireAfterSeconds](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.expireAfterSeconds) field. [source]
- Clustered collections store documents ordered by the [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) key value. The clustered index key must be `{ _id: 1 }`. [source]
- - The clustered index keys are stored with the collection. The collection size returned by the [`collStats`](https://www.mongodb.com/docs/manual/reference/command/collstats.md#mongodb-dbcommand-dbcmd.collStats) command includes the clustered index size. [source]
- By default, the [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) key values are the unique document [object identifiers.](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-objectid) [source]
- You can set your own clustered index key values, which must follow the standard constraints of [the \_id field.](https://www.mongodb.com/docs/manual/core/document.md#std-label-document-id-field) [source]
- - `"key": { _id: 1 }`, which sets the clustered index key to the `_id` field. [source]
- - `"unique": true`, which indicates the clustered index key value must be unique. [source]
- - `"name": "products clustered key"`, which sets the clustered index name. [source]
- - `"name": "stocks clustered key"`, which sets the clustered index name. [source]
- - `"name": "orders clustered key"`, which sets the clustered index name. [source]
- ```python # Use LangChain helper method to create the vector search index vector_store.create_vector_search_index( dimensions = 1024, # The dimensions of the vector embeddings to be indexed filters = [ "genre", "rating", "year" ], # The metadata fields to be indexed for filtering wait_until_complete = 60 # Number of seconds to wait for the index to build (can take around a minute) ) [source]
- You can add a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on the `timeField`, `metaField`, or measurement fields. [source]
- Starting in MongoDB 7.0, you can create a [TTL](https://www.mongodb.com/docs/manual/core/index-ttl.md#std-label-index-feature-ttl) index with a `partialFilterExpression` that relies only on the metaField. In versions prior to 6.3, you can only create TTL indexes based on the `expireAfterSeconds` parameter. [source]
- Number of TTL deletes skipped due to a TTL [secondary index](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) being present, but not valid for TTL deletion. [source]
- Collection scans, counted separately based on whether the scan uses the clustered index. [source]
- This section describes technical details and limitations for multikey indexes. [source]
- For index key length limits and per-collection index limits, see [Index Limitations.](https://www.mongodb.com/docs/manual/reference/limits.md#std-label-index-limitations) [source]
- - To review considerations for creating an index, see [Indexing Strategies.](https://www.mongodb.com/docs/manual/applications/indexes.md#std-label-manual-indexing-strategies) [source]
- - To learn about the performance impact of indexes, see [Operational Factors and Data Models.](https://www.mongodb.com/docs/manual/data-modeling/best-practices.md#std-label-data-model-indexes) [source]
- The type of query operation in the query shape affects the order of the fields used to construct the index. In general, the Performance Advisor ranks fields by their [cardinality.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-cardinality) [source]
- This page describes limitations for wildcard indexes such as incompatible properties and unsupported query patterns. [source]
- The type of query operation in the query shape affects the order of the fields used to construct the index. In general, the Performance Advisor ranks fields by their cardinality. [source]
- This section describes technical details and limitations for compound indexes. [source]
- Indexes have some negative performance impact on write operations. For collections with high write-to-read ratio, indexes are expensive since each insert must also update any indexes. For a detailed list of considerations for indexes, see [Operational Considerations for Indexes.](https://www.mongodb.com/docs/manual/data-modeling/best-practices.md#std-label-data-model-indexes) [source]
- Hashed indexes have limitations for array fields and the unique property. [source]
- If a supporting index on the `foreignField` does not exist, a `$lookup` operation that performs an equality match with a single join will likely have poor performance. For more information, see and [Lookup Performance Considerations](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#std-label-lookup-performance-considerations) and [Create an Index.](https://www.mongodb.com/docs/manual/core/indexes/create-index.md#std-label-manual-create-an-index) [source]
- If a document with a time of `2023-03-27T16:24:35Z` does not fit an existing bucket, MongoDB creates a new bucket with a minimum time of `2023-03-27T16:00:00Z` and a maximum time of `2023-03-27T16:59:59Z`. [source]
- - The set of active buckets doesn't fit within the allowed storage engine cache size. You can review this information using the [`collStats`](https://www.mongodb.com/docs/manual/reference/command/collstats.md#mongodb-dbcommand-dbcmd.collStats) database command. [source]
- - Its maximum allowed timestamp is less than the current time minus the collection's `expireAfterSeconds` parameter. This is equivalent to a [TTL collection's](https://www.mongodb.com/docs/manual/tutorial/expire-data.md#std-label-ttl-collections) time to live. [source]
- - A [`delete`](https://www.mongodb.com/docs/manual/reference/command/delete.md#mongodb-dbcommand-dbcmd.delete) or [`db.collection.deleteMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.deletemany.md#mongodb-method-db.collection.deleteMany) command deletes the last document in the bucket. [source]
- At the end of a 60-minute period, Atlas generates a 1-hour metrics report. Atlas computes the value of the Connections metric in the 1-hour report as the average of all values for the Connections metric across the 60 1-minute reports that it generates in that hour. [source]
- The Renard number series are sets of numbers derived by taking either the 5 th, 10 th, 20 th, 40 th, or 80 th root of 10, then including various powers of the root that equate to values between 1.0 to 10.0 (10.3 in the case of `R80`). [source]
- This section describes optimizations to improve the performance of [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group). There are optimizations that you can make manually and optimizations MongoDB makes internally. [source]
- Starting in version 5.2, MongoDB uses the [slot-based execution query engine](https://www.mongodb.com/docs/manual/reference/sbe.md#std-label-sbe-landing) to execute [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group) stages if either: [source]
- * The `near` parameter supports the [let option](https://www.mongodb.com/docs/manual/reference/operator/aggregation/geonear.md#std-label-geoNear_let_example) and [bound let option.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/geonear.md#std-label-geoNear_bounded_let_example) [source]
- Both the [`$`](https://www.mongodb.com/docs/manual/reference/operator/projection/positional.md#mongodb-projection-proj.-) operator and the [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/projection/elemmatch.md#mongodb-projection-proj.-elemMatch) operator project the **first** matching element from an array based on a condition. [source]
- The [`$`](https://www.mongodb.com/docs/manual/reference/operator/projection/positional.md#mongodb-projection-proj.-) operator projects the first matching array element from each document in a collection based on some condition from the query statement. [source]
- [`db.collection.find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#mongodb-method-db.collection.find) operations on [views](https://www.mongodb.com/docs/manual/core/views.md#std-label-views-landing-page) do not support [`$`](https://www.mongodb.com/docs/manual/reference/operator/projection/positional.md#mongodb-projection-proj.-) projection operator. [source]
- You must use the [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/projection/elemmatch.md#mongodb-projection-proj.-elemMatch) operator if you need separate conditions for selecting documents and for choosing fields within those documents. [source]
- Decide which fields should be encrypted and/or queryable prior to creating your collection. Changing which fields are encrypted or queryable requires rebuilding the collection's encryption schema and re-creating the collection. [source]
- Starting in MongoDB 5.1, you can specify [sharded collections](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-sharded-cluster) in the `from` parameter of [`$graphLookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphlookup.md#mongodb-pipeline-pipe.-graphLookup) stages. [source]
- Setting the `maxDepth` field to `0` is equivalent to a non-recursive [`$graphLookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphlookup.md#mongodb-pipeline-pipe.-graphLookup) search stage. [source]
- The `$graphLookup` stage does not return sorted results. To sort your results, use the [`$sortArray`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortarray.md#mongodb-expression-exp.-sortArray) operator. [source]
- If performing an aggregation that involves multiple views, such as with [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) or [`$graphLookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphlookup.md#mongodb-pipeline-pipe.-graphLookup), the views must have the same [collation.](https://www.mongodb.com/docs/manual/reference/collation.md#std-label-collation) [source]
- Regardless of the ordering of the fields in the document, the [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/projection/elemmatch.md#mongodb-projection-proj.-elemMatch) projection of an existing field returns the field after the other existing field inclusions. [source]
- - For encrypted fields with range queries enabled, review the field configuration, especially the [min, max,](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#std-label-qe-field-min-max) and [precision](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#std-label-qe-field-precision) parameters. Setting tight bounds for range queries greatly decreases the performance impact of those fields. [source]
- - [Model your data](https://www.mongodb.com/docs/manual/data-modeling.md#std-label-manual-data-modeling-intro) and prototype it to determine the actual storage and write increases for your deployment. [source]
- For the limitations of each approach, see [Queryable Encryption limitations](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/limitations.md#std-label-qe-reference-encryption-limits) or [CSFLE limitations.](https://www.mongodb.com/docs/manual/core/csfle/reference/limitations.md#std-label-csfle-reference-encryption-limits) [source]
- - MongoDB uses [schema validation](https://www.mongodb.com/docs/manual/core/schema-validation.md#std-label-schema-validation-overview) to enforce encryption of specific fields in a collection. Without a client-side schema, the client downloads the server-side schema for the collection to determine which fields to encrypt. To avoid this issue, use client-side schema validation. [source]
- For an example of CSFLE configuration for client and server-side schemas, see [CSFLE Server-Side Field Level Encryption Enforcement.](https://www.mongodb.com/docs/manual/core/csfle/fundamentals/automatic-encryption.md#std-label-field-level-encryption-automatic-remote-schema) [source]
- The [`$unset`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset.md#mongodb-pipeline-pipe.-unset) is an alias for the [`$project`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/project.md#mongodb-pipeline-pipe.-project) stage that removes/excludes fields: [source]
- 3. The [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group) stage uses `meta.type` as the group key to output one document per unique value. [source]
- You can use [causally consistent sessions](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions) to read your own writes, if the writes request acknowledgment. [source]
- - Read documents from one collection and write them to another collection using an [aggregation pipeline](https://www.mongodb.com/docs/manual/aggregation.md#std-label-aggregation-pipeline-intro) with an [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) stage or a [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) stage. [source]
- - Export collection data with [`mongodump`](https://www.mongodb.com/docs/database-tools/mongodump.md#mongodb-binary-bin.mongodump) and import the data into another collection with [`mongorestore`.](https://www.mongodb.com/docs/database-tools/mongorestore.md#mongodb-binary-bin.mongorestore) [source]
- MongoDB Atlas limits concurrent incoming connections based on the cluster tier and [class](https://www.mongodb.com/docs/atlas/customize-storage.md#std-label-storage-class-ui). MongoDB Atlas connection limits apply per node. For sharded clusters, MongoDB Atlas connection limits apply per [mongos](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-read-operations) router. The number of [mongos](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-read-operations) routers is equal to the number of replica set nodes ac [source]
- | MongoDB Atlas Cluster Tier | Maximum Connections Per Node | | --- | --- | | `Free` | 500 | | `Flex` | 500 | | `M10` | 1500 | | `M20` | 3000 | | `M30` | 3000 | | `M40` | 6000 | | `M50` | 16000 | | `M60` | 32000 | | `M80` | 96000 | | `M140` | 96000 | | `M200` | 128000 | | `M300` | 128000 | [source]
- | MongoDB Atlas Cluster Tier | Maximum Connections Per Node | | --- | --- | | `M40` | 4000 | | `M50` | 16000 | | `M60` | 32000 | | `M80` | 64000 | | `M200` | 128000 | | `M300` | 128000 | | `M400` | 128000 | | `M700` | 128000 | [source]
- | MongoDB Atlas Cluster Tier | Maximum Connections Per Node | | --- | --- | | `Free` | 500 | | `Flex` | 500 | | `M10` | 1500 | | `M20` | 3000 | | `M30` | 3000 | | `M40` | 6000 | | `M50` | 16000 | | `M60` | 32000 | | `M80` | 64000 | | `M140` | 96000 | | `M200` | 128000 | | `M300` | 128000 | [source]
- For clusters with high insert volumes, a shard key with monotonically increasing and decreasing keys can affect insert throughput. If your shard key is the `_id` field, be aware that the default values of the `_id` fields are [ObjectIds](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ObjectId) which have generally increasing values. [source]
- Aggregation pipelines support operations on sharded collections. See [Aggregation Pipeline and Sharded Collections.](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-sharded-collections.md#std-label-aggregation-pipeline-sharded-collection) [source]
- - Free clusters (formerly known as `M0`) and Flex clusters support a subset of the metrics and charts available. For complete documentation on the limitations of these clusters, see [Atlas Free Cluster Limits](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations.md#std-label-atlas-free-tier) and [Atlas Flex Limitations.](https://www.mongodb.com/docs/atlas/reference/flex-limitations.md#std-label-flex-cluster-limitations) [source]
- - Atlas pauses monitoring for Free clusters which have had no connection activity for 7 days. Monitoring resumes once a successful connection occurs through the Atlas Administration API, [Driver](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver), [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), or [Data Explorer.](https://www.mongodb.com/docs/atlas/atlas-ui.md#std-label-atlas-ui) [source]
- Pipeline stages that require more than 100 megabytes of memory to execute write temporary files to disk by default. These temporary files last for the duration of the pipeline execution and can influence storage space on your instance. [source]
- Individual `find` and `aggregate` commands can override the [`allowDiskUseByDefault`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.allowDiskUseByDefault) parameter by either: [source]
- For MongoDB Atlas, it is recommended to [configure storage auto-scaling](https://www.mongodb.com/docs/atlas/cluster-autoscaling.md#std-label-cluster-autoscaling) to prevent long-running queries from filling up storage with temporary files. [source]
- The combined results from the previous stage and the [`$unionWith`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionwith.md#mongodb-pipeline-pipe.-unionWith) stage can include duplicates. [source]
- If the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) includes a `collation` document, the operation uses that collation and ignores any other collations. [source]
- If the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) does not include a `collation` document, the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) method uses the collation for the top-level collection/view on which the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) is run: [source]
- - If the [$unionWith coll](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionwith.md#std-label-unionWith-coll) is a [view](https://www.mongodb.com/docs/manual/core/views.md), then its collation must match that of the top-level collection/view. Otherwise, the operation errors. [source]
- On systems running with [`authorization`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.authorization), the user must have the [`planCacheRead`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-planCacheRead) privilege for the collection. [source]
- For example, use the [`sh.shardCollection()`](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#mongodb-method-sh.shardCollection) method to create a new sharded collection `moviesByYearAndRating` with the `rated` field as the shard key. [source]
- However, **to replace an existing collection** regardless of the aggregation results, use [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) instead. [source]
- With the introduction of `$merge`, MongoDB provides two stages, `$merge` and [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out), for writing the results of the aggregation pipeline to a collection: [source]
- [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) can output to the same collection that is being aggregated. You can also output to a collection which appears in other stages of the pipeline, such as [`$lookup`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) [source]
- - Inequality operators such as [`$ne`](https://www.mongodb.com/docs/manual/reference/operator/query/ne.md#mongodb-query-op.-ne) or [`$nin`](https://www.mongodb.com/docs/manual/reference/operator/query/nin.md#mongodb-query-op.-nin) are range operators, not equality operators. [source]
- - If you have [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption/) enabled for a collection, Namespace Insights doesn't display the collection in this location. Atlas redacts this information. [source]
- In a Linux system, messages are subject to the rules defined in the Linux configuration file `/etc/systemd/journald.conf`. By default, log message bursts are limited to 1000 messages within a 30 second period. To see more messages, increase the `RateLimitBurst` parameter in `/etc/systemd/journald.conf`. [source]
- At a minimum, ensure that each [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance has access to two real cores or one multi-core physical CPU. [source]
- The [WiredTiger](https://www.mongodb.com/docs/manual/core/wiredtiger.md#std-label-storage-wiredtiger) storage engine is multithreaded and can take advantage of additional CPU cores. Specifically, the total number of active threads (concurrent operations) relative to the number of available CPUs can impact performance: [source]
- The threshold depends on your application. You can determine the optimum number of concurrent active operations for your application by experimenting and measuring throughput. The output from [`mongostat`](https://www.mongodb.com/docs/database-tools/mongostat.md#mongodb-binary-bin.mongostat) provides statistics on the number of active reads/writes in the (`ar|aw`) column. [source]
- The [`storage.wiredTiger.engineConfig.cacheSizeGB`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB) limits the size of the WiredTiger internal cache. The operating system uses the available free memory for filesystem cache, which allows the compressed MongoDB data files to stay in memory. In addition, the operating system uses any free RAM to buffer file system blocks and file system cache. [source]
- You can only provide one of either [`storage.wiredTiger.engineConfig.cacheSizeGB`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB) or [`storage.wiredTiger.engineConfig.cacheSizePct`.](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizePct) [source]
- - [The MySQL "swap insanity" problem and the effects of NUMA](http://jcole.us/blog/archives/2010/09/28/mysql-swap-insanity-and-the-numa-architecture/) post, which describes the effects of NUMA on databases. The post introduces NUMA and its goals, and illustrates how these goals are not compatible with production databases. Although the blog post addresses the impact of NUMA for MySQL, the issues for MongoDB are similar. [source]
- On Linux, you must disable *zone reclaim* and also ensure that your [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances are started by `numactl`, which is generally configured through your platform's init system. You must perform both of these operations to properly disable NUMA for use with MongoDB. [source]
- 2. Ensure that [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) are started by `numactl`. This is generally configured through your platform's init system. Run the following command to determine which init system is in use on your platform: [source]
- - If "`init`", your platform uses the *SysV Init* system, and you *do not* need to perform this step. The default MongoDB init script for SysV Init includes the necessary steps to start MongoDB instances via `numactl` by default. [source]
- See [Set vm.swappiness](https://www.mongodb.com/docs/manual/administration/production-notes.md#std-label-set-swappiness) for instructions on configuring swap on your Linux system following these guidelines. [source]
- If your MongoDB instance is hosted on a system that also runs other software, such as a webserver, you should choose the first swap strategy. Do *not* disable swap in this case. If possible, it is highly recommended that you run MongoDB on its own dedicated system. [source]
- For local block devices attached to a virtual machine instance via the hypervisor or hosted by a cloud hosting provider, the guest operating system should use the [none scheduler](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-none-scheduler) for best performance. The `none` scheduler allows the operating system to defer I/O scheduling to the underlying hypervisor. [source]
- For physical servers using spinning disks, the operating system should use the *mq-deadline* scheduler. The *mq-deadline* scheduler caps maximum latency per request and maintains a good disk throughput that is best for disk-intensive database applications. [source]
- MongoDB uses the [GNU C Library](http://www.gnu.org/software/libc/) (glibc) on Linux. Generally, each Linux distro provides its own vetted version of this library. For best results, use the latest update available for this system-provided version. You can check whether you have the latest version installed by using your system's package manager. For example: [source]
- If your MongoDB instance is hosted on a system that also runs other software, such as a webserver, you should set `vm.swappiness` to `1`. If possible, it is highly recommended that you run MongoDB on its own dedicated system. [source]
- - If you are running MongoDB 7.0 or earlier, [disable Transparent Hugepages](https://www.mongodb.com/docs/manual/tutorial/disable-transparent-huge-pages.md#std-label-disable-thp). In earlier versions, MongoDB performs better with typical (4096 bytes) virtual memory pages. [source]
- - Enable AWS (Amazon Web Services) [Enhanced Networking](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking) for your instance. Not all instance types support Enhanced Networking. [source]
- - Use provisioned IOPS (Input/Output Operations Per Second) for the storage, with separate devices for journal and data. Do not use the ephemeral (SSD (Solid State Disk)) storage available on most instance types as their performance changes moment to moment. (The `i` series is a notable exception, but very expensive.) [source]
- Even though the balloon driver and memory overcommitment features can negatively affect MongoDB performance under certain configurations, **do not disable these features**. If you disable these features, the hypervisor may use its swap space to fulfill memory requests, which negatively affects performance. [source]
- The Query Profiler does not include bulk operations in its query sampling and analysis. Bulk write operations are excluded from the profiled queries displayed in the Query Profiler. Excluded operations include [`bulkWrite()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.bulkWrite.md#mongodb-method-db.collection.bulkWrite), `updateMany` with multiple `stmtIds`, and similar multi-document operations. [source]
- - The [`$expr`](https://www.mongodb.com/docs/manual/reference/operator/query/expr.md#mongodb-query-op.-expr) operator allows the use of [aggregation expressions](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) within the query language. [source]
- - However, if you must create custom expressions, [`$function`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/function.md#mongodb-expression-exp.-function) is preferred over [`$where`.](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) [source]
- By default, `granularity` is set to `seconds`. You can improve performance by setting the `granularity` value to the closest match to the time span between incoming measurements from the same data source. For example, if you are recording weather data from thousands of sensors but only record data from each sensor once per 5 minutes, set `granularity` to `"minutes"`. The less frequently you append new documents, the greater the storage and performance benefits of coarser granularity. [source]
- - The document `metaField` doesn't match any active buckets. [source]
- 1. Create a metadata field. [source]
- 1) Create a metadata field. [source]
- - Defines the `metaData` field as the `metaField` of the `weather_new` collection. [source]
- - Defines the `ts` field as the `timeField` of the `weather_new` collection. [source]
- 1. Describe the documents and metadata fields. [source]
- # Define the metadata fields to filter on metadata_field_info = [ AttributeInfo( name="genre", description="The genre of the movie", type="string", ), AttributeInfo( name="year", description="The year the movie was released", type="integer", ), AttributeInfo( name="rating", description="A 1-10 rating for the movie", type="float" ), ] [source]
- The Real-Time Performance Panel (RTPP) in the Atlas UI provides insights into current network traffic, database operations, and hardware statistics about the hosts at a one second granularity in the Atlas UI. We recommend that you use RTPP (Real-Time Performance Panel) to: [source]
- The Organization Activity Feed and Project Activity Feed in the Atlas UI list all events that occur for a given Atlas organization or project, respectively. You can filter each activity feed for event type and time range to monitor events such as API access updates, alert configuration changes, and more. This allows you to review activity records for your organization or project at your desired level of granularity. [source]
- A histogram of the `batchSize` cursor option values set on change stream [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate) and [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getmore.md#mongodb-dbcommand-dbcmd.getMore) commands, with bucket boundaries at 1, 10, 100, 1000, and 10000. [source]
- A histogram of the `maxTimeMS` cursor option values set on change stream [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate) and [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getmore.md#mongodb-dbcommand-dbcmd.getMore) commands, with bucket boundaries at 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, and 1000000. [source]
- | `granularity` | Covered Time Span | | --- | --- | | `"seconds"` (default) | one hour | | `"minutes"` | 24 hours | | `"hours"` | 30 days | [source]
- These data may provide a finer level of granularity than the utilities discussed above. Consider using their output in scripts and programs to develop custom alerts, or to modify the behavior of your application in response to the activity of your instance. The [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp) method is another useful tool for identifying the database instance's in-progress operations. [source]
- Atlas stores metrics data at various granularity levels. For each granularity level, Atlas computes metrics as averages of the reported metrics at the next finer granularity level. [source]
- Atlas gathers metrics data at a 1-minute granularity unless you qualify for premium monitoring. However, Atlas gathers Replication Lag and Replication Headroom metrics at an 85-second granularity. [source]
- Many metrics have a burst reporting equivalent. The value of a burst reporting metric at a given granularity is the maximum reported value from all the reports Atlas generates at the next finer granularity level during that interval. [source]
- If you have at least one cluster that's `M40` or larger, Atlas automatically enables premium monitoring for all clusters in the project. With premium monitoring enabled, Atlas gathers metrics data at a 10-second granularity. Premium monitoring remains enabled for all clusters in the project until you downgrade or terminate your last `M40` cluster. [source]
- - A [default](https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket.md#std-label-bucket-default) value is specified to bucket documents whose `groupBy` values are outside of the `boundaries` or of a different [BSON type](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-bson-types) than the values in `boundaries`. [source]
- The following example sets the `granularity` of a `weather24h` collection to `minutes`: [source]
- - `bucketMaxSpanSeconds` sets the maximum time between timestamps in the same bucket. Possible values are 1-31536000. [source]
- 4. The associated client session tracks these two time fields. [source]
- Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. [source]
- - The `granularity` has fewer intervals than the number of `buckets`. [source]
- The same approach is applied to the other Renard series to offer finer granularity, i.e., more intervals between 1.0 and 10.0 (10.3 for `R80`). [source]
- Different values for `granularity` are substituted into the following operation: [source]
- | Granularity | Results | Notes | | --- | --- | --- | | No granularity | **{ "_id" : { "min" : 0, "max" : 20 }, "count" : 20 }****{ "_id" : { "min" : 20, "max" : 40 }, "count" : 20 }****{ "_id" : { "min" : 40, "max" : 60 }, "count" : 20 }****{ "_id" : { "min" : 60, "max" : 80 }, "count" : 20 }****{ "_id" : { "min" : 80, "max" : 99 }, "count" : 20 }** | | | R20 | **{ "_id" : { "min" : 0, "max" : 20 }, "count" : 20 }****{ "_id" : { "min" : 20, "max" : 40 }, "count" : 20 }****{ "_id" : { "min" : 40, "max" : 63 }, "count" : 23 }****{ "_id" : { "min" : 63, "max" : 90 }, "count" : 27 }****{ "_id" : [source]
- You can filter the charts by stream processor name, time range, and granularity. [source]
- Time has moved forward or backward past the covered time span, as indicated by an incoming document timestamp that falls outside of the bucket's bounds. These bounds are determined by the collection's granularity setting. [source]
- - You can only match on the `metaField` field value. [source]
- - You can only modify the `metaField` field value. [source]
- - `metaField` can be either a: [source]
- metaField: { sensorId: 5578, type: "temperature" }, [source]
- "metaField.sensorId": 5578, [source]
- "metaField.type": "temperature" [source]
- metaField: { sensorId: 5578, type: 'temperature' }, [source]
- `$rankFusion` orders results according to the Reciprocal Rank Fusion (RRF) Formula. This stage places the RRF score for each document in the `score` metadata field of the output results. The RRF formula ranks documents with a combination of the following factors: [source]
- The `score` metadata field for `Document1` is `0.0322664585`. [source]
- The following steps demonstrate how to create and run an aggregation pipeline to unpack array fields into separate documents and compute new values based on groups of common values. [source]
- 1) Add an unwind stage to unpack the array of product orders. [source]
- 1. Add an unwind stage to unpack the array of product orders. [source]
- If the attempt is unsuccessful, MongoDB applies a set of rules to decide whether the multi-planner should continue or if CBR should evaluate the plans to determine the optimal solution. CBR evaluates each node in a plan based on a cost function and its cardinality estimations. MongoDB selects the plan with the lowest overall cost as the winning plan. Currently, MongoDB only invokes the CBR for a small amount of queries. [source]
- The overview is based on [sampling](https://www.mongodb.com/docs/compass/sampling.md#std-label-compass-sampling) the documents in the collection. The schema overview may include additional data about the contents of the fields, such as the minimum and maximum values of dates and integers, the frequency of occurrence of particular values, and the cardinality of the data. [source]
- Aggregation operations with the [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate) command have the following limitations. [source]
- Flex clusters don't support this feature at this time. To learn more, see [Atlas Flex Limitations.](https://www.mongodb.com/docs/atlas/reference/flex-limitations.md#std-label-flex-cluster-limitations) [source]
- Single-region deployments have no unique considerations for integrations with third-party alerting tools, such as [Datadog](https://www.mongodb.com/docs/atlas/tutorial/datadog-integration.md#std-label-datadog-integration) and [Prometheus](https://www.mongodb.com/docs/atlas/tutorial/prometheus-integration.md#std-label-prometheus-integration). See [All Deployment Paradigm Recommendations.](https://www.mongodb.com/docs/atlas/architecture/current/monitoring-alerts.md#std-label-arch-center-monitoring-alerts-recs-for-any-deployment) [source]
- For prompting best practices and example prompts, see the [Natural Language to MongoDB Queries guide.](https://www.mongodb.com/docs/manual/natural-language-to-mongodb.md#std-label-natural-language-to-mongodb) [source]
- This document provides a collection of hard and soft limitations of the MongoDB system. The limitations on this page apply to deployments hosted in Atlas and self-hosted MongoDB deployments, unless specified otherwise. [source]
- The following limitations apply only to deployments hosted in MongoDB Atlas. If any of these limits present a problem for your organization, contact [Atlas support.](https://www.mongodb.com/docs/atlas/support/) [source]
- - MongodB 5.0 adds improved support for the use of (`$`) and (`.`) in field names. There are some restrictions. See [Field Name Considerations](https://www.mongodb.com/docs/manual/core/dot-dollar-considerations.md#std-label-crud-concepts-dot-dollar-considerations) for more details. [source]
- Number of times histogram-based cardinality estimation was used. [source]
- Number of times sampling-based cardinality estimation was used. [source]
- Number of times heuristic-based cardinality estimation was used. [source]
- Number of times a mixed approach to cardinality estimation was used. [source]
- Number of times metadata-based cardinality estimation was used. [source]
- Similar to duplicate field names, the same considerations apply for duplicate operators used in the query. [source]
- Confirm that your workload fits the [public preview limitations](https://www.mongodb.com/docs/atlas/infinite/atlas-infinite-landing.md#std-label-atlas-infinite-availability) first. [source]
- [MongoDB Atlas](https://www.mongodb.com/atlas/database) is a cloud-hosted database-as-a-service. If you can leverage public clouds, Atlas automatically addresses many of the considerations present in these Production Notes, as well as offering the following benefits: [source]
- See the [Replica Set Architectures](https://www.mongodb.com/docs/manual/core/replica-set-architectures.md#std-label-replica-set-architecture) document for an overview of architectural considerations for replica set deployments. [source]
- For details, see the [Redaction](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/limitations.md#std-label-qe-redaction) section of this page. [source]
- Production Considerations (Sharded Clusters) [source]
- - The field you choose for your hashed shard key should have a high [cardinality](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key.md#std-label-shard-key-range), meaning a large number of different values. [source]
- **Important: Please read the following considerations before you enable the Query Profiler.** [source]
- For details on `$lookup` performance by operation type, see [Performance Considerations.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#std-label-lookup-performance-considerations) [source]
- You may experience performance limitations from inadequate or inappropriate indexing strategies or poor schema design patterns. [Locking Performance](https://www.mongodb.com/docs/manual/administration/analyzing-mongodb-performance.md#std-label-analyzing-performance-locks) discusses how these can impact MongoDB's internal locking. [source]
Related concepts
- metaField cardinality — is a problem of MongoDB time-series indexes and metaField design
- metaField — is a part of MongoDB time-series indexes and metaField design
- index — is a related of MongoDB time-series indexes and metaField design
- secondary index on time series — is a part of MongoDB time-series indexes and metaField design
- working set for time series — is a measure of MongoDB time-series indexes and metaField design
- time series query — is a part of MongoDB time-series indexes and metaField design
- time series sharding — is a related of MongoDB time-series indexes and metaField design
- block processing — is a part of MongoDB time-series indexes and metaField design
Children
- No children recorded.