<!-- llms-explorer concept facts · https://llms-explorer.com/tree/mongodb-time-series-query-execution/ · pack 2026-10-19 · ~20409 tokens -->

# MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts

> Time series collections use [zstd](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-zstd) compression, which differs from the global default compression algorithm, [snappy.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-snappy) (from www.mongodb.com)

Parent: [Global AI Hub Research Corpus](https://llms-explorer.com/tree/global-ai-hub-research-corpus/) · 9 facets · 249 facts · page: https://llms-explorer.com/tree/mongodb-time-series-query-execution/

## Definitions

- For more information on running database commands from the C# Driver, refer to the [Run a Database Command](https://www.mongodb.com/docs/drivers/csharp/current/run-command/) page in the Node.js Driver documentation. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- For more information on running database commands from the Java Driver, refer to the [Run a Database Command](https://www.mongodb.com/docs/drivers/java/sync/current/command/) page in the Java Driver documentation. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- For more information on running database commands from the Node.js Driver, refer to the [Run a Database Command](https://www.mongodb.com/docs/drivers/node/current/run-command/) page in the Node.js Driver documentation. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- For more information on running database commands from the Java Driver, refer to the [Run a Database Command](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/run-command/) page in the PyMongo Driver documentation. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- If an index uses prefix compression (which is the [`default for WiredTiger`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--wiredTigerIndexPrefixCompression)), the returned size reflects the compressed size. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.totalIndexSize.md#definition)
- Time series data is a sequence of data points in which insights are gained by analyzing changes over time. — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md)

## Structure and components

- In a regular collection, data is stored sequentially as blocks on disk, optimizing write speed. However, it requires one index for each data point, which quickly grows very large. It also requires a second index that contains the time series identifier and timestamps themselves, so that users can query for a single series. To read this data, MongoDB has to process all of the database and disk blocks that contain it, even if a block only contains a single relevant document. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#comparing-time-series-collections-to-regular-collections)
- Each document you insert should contain a single measurement. To insert multiple documents at once, use the [`db.collection.insertMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertmany.md#mongodb-method-db.collection.insertMany) method: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#insert-measurements-into-a-time-series-collection)
- Before any metadata compaction, the `ESC` and `ECOC` contain one metadata document for every field/value pair of every indexed field. Indexing one encrypted field/value pair across 1000 documents requires 1000 documents in the `ESC` and 1000 documents in the `ECOC`. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections.md#storage-costs-for-equality-queryable-fields)
- | Database Tool Name | Description | | --- | --- | | `list-databases` | Displays all databases available in your MongoDB deployment with their storage sizes. | | `list-collections` | Shows all collections within a specific database. | | `find` | Retrieves actual documents from a collection that match specific search criteria. | | `count` | Quickly returns the total number of documents in a collection without retrieving the documents themselves. | | `aggregate` | Performs complex data processing operations like grouping, filtering, transforming, and calculating statstics across documents. | | ` — [source](https://www.mongodb.com/docs/compass/query-with-natural-language/compass-ai-assistant.md#database-tools)
- | Field | Necessity | Description | | --- | --- | --- | | [field](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#std-label-densify-field) | Required | The field to densify. The values of the specified `field` must either be all numeric values or all dates. Documents that do not contain the specified `field` continue through the pipeline unmodified. To specify a `<field>` in an embedded document or in an array, use [dot notation.](https://www.mongodb.com/docs/manual/core/document.md#std-label-document-dot-notation) For restrictions, see [`field` Restrictions.](htt — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#syntax)
- The following example shows the `stocks` time series collection structure used in this quick start. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md#sample-data)
- The result document contains a document for the time series collection which contains the `options.expireAfterSeconds` field. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#retrieve-the-current-value-of-expireafterseconds)
- This page shows how to create and query a time series collection. The code examples provided create and work with sample weather data that contains time, temperature, and sensor information. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md)
- | Field Name | Data Type | Description | | --- | --- | --- | | `ns` | string | Namespace of the sharded collection. | | `shards` | array | Shards in the collection with the data distribution information for each shard. | | `shards.numOrphanedDocs` | integer | Number of orphaned documents in the shard. For [time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), `numOrphanedDocs` contains the number of orphaned measurement buckets in the shard. | | `shards.numOwnedDocuments` | integer | Number of documents owned by the — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution.md#output-fields)

## How it works

- Working set is the subset of data and indexes touched in a typical window, rarely the whole database. Practitioner guidance is to size the cache to working set plus write headroom, and to use a sustained post-warmup page-fault rate as a proxy when the size is unknown. — [source](https://www.netdata.cloud/guides/mongodb/mongodb-cache-undersized-working-set/)
- During 8.0 development, Jira SERVER-88316 (fixed in 8.0.0-rc0) showed the server using block processing for a GroupByNull test case with only featureFlagSbeFull set, when the test expected none. This shows the block-processing decision depended on several feature flags. — [source](https://jira.mongodb.org/browse/SERVER-88316)
- - In [time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), documents do not require a unique [\_id](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-_id) field because MongoDB does not create an index on the `_id` field. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#properties-of-time-series-data)
- In time series collections, documents do not require a unique _id field because MongoDB does not create an index on the _id field. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing/)
- When you run `$collStats` on a time series collection with the `storageStats: {}` option, the output includes time series data. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-output-on-time-series-collections)
- [`timeseries`](https://www.mongodb.com/docs/manual/reference/command/collstats.md#mongodb-data-collStats.timeseries) appears when you run the `collStats` command on a [time series collection.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/reference/command/collStats.md#output)
- When migrating or backfilling into a time series collection, always insert the documents in order, from oldest to newest. In this case, [`mongodump`](https://www.mongodb.com/docs/database-tools/mongodump.md#mongodb-binary-bin.mongodump) exports documents in natural order and the `--maintainInsertionOrder` option for [`mongorestore`](https://www.mongodb.com/docs/database-tools/mongorestore.md#mongodb-binary-bin.mongorestore) guarantees the same insertion order for documents. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- When you create a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), you can set up automatic removal of documents older than a specified number of seconds by using the `expireAfterSeconds` property: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md)
- When you create a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), you can set up automatic removal of documents older than a specified number of seconds by using the `expireAfterSeconds` parameter: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#disable-automatic-removal)
- Time series collections efficiently store time series data. Writes are organized so that data from the same source is stored alongside other data points from a similar point in time. — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#time-series-collections)
- When the collection you specify to [`sh.shardCollection()`](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#mongodb-method-sh.shardCollection) is a time series collection, you do not need to specify the [timeseries](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#std-label-method-sharded-time-series-collection-options) option. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#shard-an-existing-time-series-collection)

## How-to and procedures

- Use the [`shardCollection()`](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#mongodb-method-sh.shardCollection) method with the [timeseries](https://www.mongodb.com/docs/manual/reference/method/sh.shardcollection.md#std-label-method-sharded-time-series-collection-options) option. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#create-a-sharded-time-series-collection)
- Enable sharding on your collection by creating an index that supports the [shard key.](https://www.mongodb.com/docs/manual/core/sharding-shard-key.md#std-label-shard-key) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#shard-an-existing-time-series-collection)
- Run the following command to create a hashed index on the `metadata.location` field: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#shard-an-existing-time-series-collection)
- To shard a time series collection, you must [deploy a sharded cluster](https://www.mongodb.com/docs/manual/tutorial/deploy-shard-cluster.md#std-label-sharding-procedure-setup) to host the database that contains your time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#prerequisites)
- To learn more about the fields returned in the `timeseries: {}` document, see [bucketCatalog.](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#std-label-server-status-bucketcatalog) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-output-on-time-series-collections)
- Create your collection with your desired time series settings using the [`db.createCollection()`](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#mongodb-method-db.createCollection) method. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- To run the complete aggregation pipeline to migrate the data into the new time series collection, call one of the methods that implements `IEnumerable`, such as `ToList`, `ToArray`, or `ToEnumerable` on the pipeline object. The following example shows the complete aggregation pipeline, including this final step: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- Add an [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) aggregation stage to your pipeline to create a time series collection and insert your data into it. The pipeline below performs the following operations: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- Run the complete aggregation pipeline to migrate the data into the new time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- Use the following steps to migrate data from an existing collection to a time series collection with [`mongodump`](https://www.mongodb.com/docs/database-tools/mongodump.md#mongodb-binary-bin.mongodump) and [`mongorestore`.](https://www.mongodb.com/docs/database-tools/mongorestore.md#mongodb-binary-bin.mongorestore) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md)
- To create a new [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), issue the following command in the [`mongosh`:](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- To export your data from an existing collection that is not of type `timeseries` use [`mongodump`.](https://www.mongodb.com/docs/database-tools/mongodump.md#mongodb-binary-bin.mongodump) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- To import your data into a timeseries collection, use [`mongorestore`.](https://www.mongodb.com/docs/database-tools/mongorestore.md#mongodb-binary-bin.mongorestore) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- To enable automatic removal of documents on a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) that doesn't have an expiration, or to modify the expiration time on an existing collection, change the `expireAfterSeconds` parameter value, using the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#create-or-change-expiration-time)
- To retrieve the current value of `expireAfterSeconds`, use the `ListCollectionsAsync` method. The result document contains the `options.expireAfterSeconds` field for the timeseries collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#retrieve-the-current-value-of-expireafterseconds)
- To retrieve the current value of `expireAfterSeconds`, use the `listCollections` method. The result document contains the `options.expireAfterSeconds` field for the timeseries collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#retrieve-the-current-value-of-expireafterseconds)
- To enable automatic removal of documents for an existing [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), issue the following [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#enable-automatic-removal-on-a-collection)
- To retrieve the current value of `expireAfterSeconds`, use the `list_collections` method. The result document contains the `options.expireAfterSeconds` field for the timeseries collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#retrieve-the-current-value-of-expireafterseconds)
- To return one document from a time series collection, you use a [FilterDefinitionBuilder\<TDocument>](|api-root|/MongoDB.Driver/MongoDB.Driver.FilterDefinitionBuilder-1.html) to create a filter to match a document. You pass the filter to the `Find()` method of the `IMongoCollection<TDocument>` class. The following example creates a FilterDefinition and also uses a ProjectionDefinition to omit the `_id` field from the results. It returns a `List<BsonDocument>`. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- To return one document from a time series collection, you can use the `findOne()` method. This returns a [cursor.](https://www.mongodb.com/docs/manual/core/cursors.md#std-label-cursors) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- To return one document from a time series collection, you can use the `findOne()` method. The following example uses the `projection` field in the query to omit the `_id` field from the returned documents: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- To return one document from a time series collection, you can use the `find_one()` method. This returns a [cursor.](https://www.mongodb.com/docs/manual/core/cursors.md#std-label-cursors) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- To return one document from a time series collection, you can use the [`db.collection.findOne()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.findone.md#mongodb-method-db.collection.findOne) method. The following example uses the `projection` field in the query to omit the `_id` field from the returned documents: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- Create and Query a Time Series Collection — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections/)
- To list all time series collections in a database, use the [`listCollections`](https://www.mongodb.com/docs/manual/reference/command/listcollections.md#mongodb-dbcommand-dbcmd.listCollections) command with a filter for `{ type: "timeseries" }`: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-check-type.md#procedure)
- To automatically delete old data, [set up automatic removal (TTL).](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#std-label-set-up-automatic-removal) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#updates)
- Use the following pages to create and configure your time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-create-configure.md)
- Use this tutorial to shard a new or existing time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md)

## Examples and snippets

- ```java — `// Create an aggregation pipeline` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- ```javascript — `const pipeline = [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- ```python — `pipeline = [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- ```javascript — `db.weather.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- ```javascript — `"ns" : <string>,` … — [source](https://www.mongodb.com/docs/manual/reference/command/collStats.md#output)
- ```javascript — `db.weather.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-time-series-data)
- ```javascript — `_id: ObjectId("<object-id>"),` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-time-series-data)
- ```javascript — `bucketsNs: 'test.weather',` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-on-time-series-collections)
- ```csharp — `var query =` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- ```java — `Date target = Date.from(Instant.parse("2045-11-19T18:00:00Z"));` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- ```javascript — `catalogStats: {` … — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#catalogstats)
- ```json — `"cursor": {` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#retrieve-the-current-value-of-expireafterseconds)
- ```javascript — `db.runCommand( {` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-check-type.md#procedure)
- ```javascript — `db.dowJonesTickerData.aggregate( [ {` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#calculate-average-price-per-month)
- ```python — `pipeline_results = stocks_coll.aggregate(` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#calculate-average-price-per-month)
- ```java — `// Create the compound _id with $dateTrunc and symbol` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#calculate-average-price-per-month)
- ```javascript — `const pipeline = [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#calculate-average-price-per-month)
- ```none — `$dateTrunc: {` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#definition)
- ```javascript — `db.cakeSales.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#truncate-order-dates-in-a-project-pipeline-stage)
- ```javascript — `db.cakeSales.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#truncate-order-dates-and-obtain-quantity-sum-in-a-group-pipeline-stage)

## Measurements and reference values

- A MongoDB staff forum answer (March 2022) gave an informal rule of thumb of RAM at 15-20% of total data size, covering indexes, working set, queries and OS. It is not an official time-series formula and cites MongoDB 4.0 docs. — [source](https://www.mongodb.com/community/forums/t/working-set-should-be-sized-to-fit-into-ram-or-wiredtiger-internal-cache/140684)
- A forum report with indexes on t/c in both directions shows a range filter { c: x, t: { $lte: ... } } with sort { t: -1 } spending IXSCAN ~4s but FETCH ~2-5 minutes, while a similar $gte ascending query took ~1s; no answer was given, version unstated. — [source](https://www.mongodb.com/community/forums/t/filter-on-time-series-with-lte-on-timestamp-and-reverse-index-is-too-slow/296074)
- The maximum size for documents within a time series collection is 4 MB. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#document-size)

## Problems, failure modes and limitations

- MongoDB automatically enables block processing for eligible time series queries. You cannot manually specify whether a query uses block processing. To see if your time series query uses block processing, see [`stages`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.slotBasedPlan.stages) in the explain plan output. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#block-processing)
- To check whether a query used block processing, inspect explain output at queryPlanner.winningPlan.slotBasedPlan.stages. A slotBasedPlan field means SBE ran the query. Slow-query logs carry a queryFramework field with value sbe or classic. The docs show no example of what block-processing stages look like. — [source](https://www.mongodb.com/docs/v8.2/core/timeseries/timeseries-querying/)
- Block processing is automatic. Users cannot enable or disable it for a single query. Eligibility is decided per query, and queries with unsupported operators or expressions run on the classic engine. SBE support is version specific and still changing. — [source](https://www.mongodb.com/docs/v8.2/core/timeseries/timeseries-querying/)
- Default WiredTiger internal cache is the larger of 50% of (RAM - 1 GB) or 256 MB. MongoDB advises against raising it above the default, and in containers it must be set below the container's RAM limit. — [source](https://www.mongodb.com/docs/manual/faq/storage/)
- Undersized-cache signals per one monitoring vendor: sustained fill above ~80% with rising eviction rates, dirty ratio above 15% (warning) or 20% (critical), and application-thread evictions. These thresholds are vendor heuristics, not MongoDB documentation. — [source](https://www.netdata.cloud/guides/mongodb/mongodb-cache-undersized-working-set/)
- You cannot run sharding administration commands on sharded time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#sharding-administration-commands)
- | Field | Type | Description | | --- | --- | --- | | `distanceField` | string | The output field that contains the calculated distance. To specify a field within an embedded document, use [dot notation.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-dot-notation) This field is required for queries on timeseries collections. Starting in MongoDB 8.1, `distanceField` is optional for queries on non-timeseries collections. | | `distanceMultiplier` | number | Optional. The factor to multiply all distances returned by the query. For example, use the `distanceMultiplier` to conver — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear.md#definition)
- For time series collections, TTL indexes also remove a bucket of data when all documents inside it expire. This is equal to the upper timestamp limit of the bucket, plus the `expireAfterSeconds` value. For example, if a bucket covers data up until `2023-03-27T18:29:59Z` and `expireAfterSeconds` is 300, the TTL index expires the bucket after `2023-03-27T18:34:59Z`. — [source](https://www.mongodb.com/docs/manual/core/index-ttl.md#expiration-of-data)
- Ensure that you run the `mongorestore` command with the [`--noIndexRestore`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--noIndexRestore) option. `mongorestore` cannot create indexes on time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- Starting in MongoDB 8.3, creating an index with the name of `"_id_"` or specifying a hint of `"_id_"` on time series collections returns an error. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#hint-on-id-index)
- If you specify a modification in the `timeseries` parameter of your `collMod` operation, you cannot use other modification options in the same command. You must perform time series modifications in a dedicated command that is separate from other collection modifications. — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#modify-time-series-collections)
- If MongoDB cannot obtain the sort order with an index scan, then MongoDB uses a top-k sort algorithm. This algorithm buffers the first `k` results (or last, depending on the sort order) seen so far by the underlying index or collection access. If the memory footprint of these `k` results exceeds 100 megabytes, MongoDB automatically writes temporary files to disk unless the query specifies [`cursor.allowDiskUse()`](https://www.mongodb.com/docs/manual/reference/method/cursor.allowdiskuse.md#mongodb-method-cursor.allowDiskUse) with a value of `false` (in which case, the query fails). — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.sort.md#limit-results)
- Limits the amount of memory that simultaneous [index builds](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-build-process) on one collection may consume for their duration. The specified amount of memory is shared between all indexes built using a single [`createIndexes`](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#mongodb-dbcommand-dbcmd.createIndexes) command or its shell helper [`db.collection.createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Rolling indexes build indexes on the applicable nodes sequentially and may reduce the performance impact of an index build if your deployment's average CPU utilization exceeds (N-1)/N-10% where N is the number of CPU threads available to mongod of if the WiredTiger cache fill ratio regularly exceeds 90%. If your deployment does not meet this criteria, use the default index build. You can't create a rolling index on an M0 free cluster or M2/M5 shared cluster. — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-rollingIndex.md)
- You can't use the `query` field for `$geoNear` on a [time series collection.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#geonear)
- You cannot use the [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) aggregation stage to add data from another collection to a time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#merge)
- | `$out` | [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) | | --- | --- | | Can output to a collection in the same or different database. | Can output to a collection in the same or different database. | | Creates a new collection if the output collection does not already exist. | Creates a new collection if the output collection does not already exist. | | Replaces the output collection completely if it already exists. | Can incorporate results (insert new documents, merge documents, replace documents, keep existing documen — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#comparison-with-merge)
- You cannot create a time series collection as a [capped collection.](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#capped-collections)
- - You cannot convert an existing collection into a time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#modification-of-collection-type)
- - You cannot convert a time series collection into a different collection type. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#modification-of-collection-type)
- You cannot write to time series collections in [transactions.](https://www.mongodb.com/docs/manual/core/transactions.md#std-label-transactions) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#transactions)
- If the time between the end of the to-be-rolledback instance's oplog and the first operation after the common point (the last point where the source node and the to-be-rolledback node had the same data) exceeds this value, the rollback will fail. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#replication-and-consistency)

## Comparisons and alternatives

- MongoDB's blog (published 2024-12-09, updated 2025-07-21) claims 10-40x improvements across workloads, up to 100x for some large aggregations, and 20x ops/sec versus 7.0 in a worked example. The example ran on an Atlas M50 using MongoDB's TSBS fork: about 6 million events, a 24-hour $match, $sort, $group with $dateTrunc, $setWindowFields and $expMovingAvg. — [source](https://mongodb.com/company/blog/technical/key-enhancements-mongodb-8-0-block-processing)
- Delta Encoding takes advantage of the data in your time series collection having time-series characteristics. Instead of storing absolute values, Delta Encoding assumes that the measurements will not change rapidly between each other. This approach reduces the amount of information required by only storing the difference between measurements. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-compression.md#delta-encoding-delta-compression)
- Starting in version 8.0, MongoDB may execute certain time series queries using block processing. This performance improvement processes queries in "blocks" of data, rather than individual values. Block processing improves query execution speed and throughput when working with time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#block-processing)
- Time series collections use [zstd](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-zstd) compression, which differs from the global default compression algorithm, [snappy.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-snappy) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-compression.md#default-compression-algorithm)
- MongoDB does not create an index on the `_id` field when you create a time series collection. This differs from regular collections which have an index on the `_id` field by default. Commands that specify a hint on the `_id` field on time series collections return an error unless you manually create an index on the `_id` field. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#default-index)
- Allegro's 5.0.3 benchmark found aggregation over a random six-hour window 23-48% faster on a time series collection than a regular one (10K to 100K queries), but single-timestamp lookups were nearly equal (16.854s vs 16.038s for 1M queries). — [source](https://blog.allegro.tech/2021/12/performance-evaluation-of-timeseries.html)

## Facts and statements

- Starting in MongoDB 8.0, if a query uses [block processing](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#std-label-timeseries-querying-block-processing), `block_to_row` and `ts_bucket_to_cellblock` appear in the `stages` output. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- The SBE reference page says SBE is disabled automatically on collections that have an index with a hashed-field prefix followed by a non-hashed field, with both fields in the index. Ineligible queries fall back to the classic engine. The page does not tie this rule to time series specifically. — [source](https://mongodb.com/docs/v8.0/reference/sbe)
- Collection data in the WiredTiger cache is uncompressed, so block compression saves disk but not cache space; the OS filesystem cache holds the compressed on-disk form. Indexes in cache still benefit from prefix compression. Compressed time series storage size therefore understates the cache footprint of hot buckets. — [source](https://www.mongodb.com/docs/manual/faq/storage/)
- MongoDB's docs state a bucket holds at most 1000 measurements or 125 KiB, whichever is lower, and MongoDB may enforce a lower maximum for high-cardinality data so the working set of buckets fits in the WiredTiger cache. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing/)
- Connect [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) to the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) for your sharded cluster. Specify the `host` and `port` on which the `mongos` is running: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#create-a-sharded-time-series-collection)
- - Shards a new time series collection named `weather` on the `test` database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#create-a-sharded-time-series-collection)
- This page describes how MongoDB compresses data in time series collections, and how you can optimize compression. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-compression.md)
- Starting in MongoDB 5.2, time series collections use **column compression**. Column compression adds a number of innovations that work together to significantly improve practical compression, reduce your data's overall storage on disk, and improve read performance. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-compression.md#column-compression)
- This weather data time series collection deletes documents after 24 hours: — [source](https://www.mongodb.com/docs/manual/core/index-ttl.md#create-a-ttl-index)
- **Note: In-progress Indexes** — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-on-time-series-collections)
- The returned `storageStats` includes information about indexes being built. For details, see: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-on-time-series-collections)
- This is distinct from using the [`index`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-collflag-index) option with the `expireAfterSeconds` property to change the expiration time for a [TTL Collection.](https://www.mongodb.com/docs/manual/tutorial/expire-data.md#std-label-ttl-collections) — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#modify-time-series-collections)
- - `TS_MODIFY` for modifying a time series collection — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- For operations on time series collections, the type of operation. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of buckets unpacked to resolve the operation. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of documents deleted. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of documents inserted. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of documents matched. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of documents modified. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For operations on time series collections, the number of documents upserted. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- 3. Create a hashed index on your collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#shard-an-existing-time-series-collection)
- Zone sharding does not support time series collections. The balancer always distributes data in sharded time series collections evenly across all shards in the cluster. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-considerations.md#zone-sharding)
- - To shard a time series collection, see [Shard a Time Series Collection.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#std-label-manual-timeseries-shard-collection) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md#next-steps)
- > Derived 2026-10-19; topic-filtered subset of mongodb.com-docs-query.md: Server manual pages about queries, indexes, aggregation, time series, profiling, explain, parameters and 7.x–9.0 release notes, plus Compass query/explain/index pages and Atlas performance/query pages. Third-party text; private reading aid; never publish. — source: `~/.claude/skills/web-text-mirror/text-mirror/mongodb.com-docs-query-core.md`
- - Data is indexed by time and an identifier, such as a stock ticker, that identifies the unique time series it belongs to. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#properties-of-time-series-data)
- - On a [time series collections](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-time-series-collection), you can only specify hints using the index name, not the index key pattern. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md#behavior)
- ```javascript 2021-06-01T16:50:56.639+0200 checking for collection data in timeseries/weather/temporarytimeseries.bson 2021-06-01T16:50:56.640+0200 restoring to existing collection weather.weathernew without dropping 2021-06-01T16:50:56.640+0200 reading metadata for weather.weathernew from timeseries/weather/temporarytimeseries.metadata.json 2021-06-01T16:50:56.640+0200 restoring weather.weathernew from timeseries/weather/temporarytimeseries.bson 2021-06-01T16:51:01.229+0200 no indexes to restore 2021-06-01T16:51:01.229+0200 finished restoring weather.weathernew (10000 documents, 0 failu — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- In the following output, the [`$densify`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#mongodb-pipeline-pipe.-densify) stage fills in the gaps of time between the hours of `00:00:00` and `08:00:00`. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-time-series-data)
- This model is optimized for [CRUD](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CRUD) operations and frequent updates. A bank account balance only needs to reflect the current state, so each account holder's document is updated as that information changes. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#comparing-time-series-collections-to-regular-collections)
- | Industry | Examples | | --- | --- | | Internet of Things (IoT) | Sensor data (for example, smart home devices or fleet logistics); Machine learning and artificial intelligence scraping | | Financial Services | High frequency trading; Financial quantitative analysis; Banking data (for example, accounting of banking transactions over time); Stock market data | | Retail and E-Commerce | Transaction, sales, and price analysis; Inventory management | | DevOps | Application logging; Infrastructure and network monitoring | — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#example-use-cases)
- The following example creates a database named `timeseries` and stores a reference to it under `timeSeriesDB`. It then create a timeseries collection named `weather` in that database and stores a reference to it under the same name: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- The following example uses a database named `timeseries` and stores a reference to it under `timeSeriesDB`. It then create a timeseries collection named `weather` in that database and stores a reference to it under the same name: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#configure-a-time-series-collection)
- For additional query functionality, you can use the `Aggregate()` method to run an [aggregation pipeline.](https://www.mongodb.com/docs/manual/core/aggregation-pipeline.md#std-label-aggregation-pipeline) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- This example groups all documents by the date of the measurement, then calculates the average of all temperature measurements that day and returns a [cursor:](https://www.mongodb.com/docs/manual/core/cursors.md#std-label-cursors) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- For additional query functionality, you can use the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) method to run an [aggregation pipeline.](https://www.mongodb.com/docs/manual/core/aggregation-pipeline.md#std-label-aggregation-pipeline) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#run-aggregations-on-a-time-series-collection)
- After MongoDB builds your index, return to your notebook and run vector search queries on your data. The following examples demonstrate different queries that you can run on your vectorized data. — [source](https://www.mongodb.com/docs/atlas/ai-integrations/llamaindex.md#run-vector-search-queries)
- Increasing the value of `maxNumActiveUserIndexBuilds` allows additional concurrent index builds at the cost of increased pressure on the WiredTiger cache. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- [`storageSize`](https://www.mongodb.com/docs/manual/reference/command/collstats.md#mongodb-data-collStats.storageSize) does not include index size. See [`totalIndexSize`](https://www.mongodb.com/docs/manual/reference/command/collstats.md#mongodb-data-collStats.totalIndexSize) for index sizing. — [source](https://www.mongodb.com/docs/manual/reference/command/collStats.md#output)
- Defines the maximum size of the internal cache that WiredTiger uses for all data. The memory consumed by an index build (see [`maxIndexBuildMemoryUsageMegabytes`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.maxIndexBuildMemoryUsageMegabytes)) is separate from the WiredTiger cache memory. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#wiredtiger-options)
- Defines the maximum amount of memory to allocate for cache as a percentage of physical RAM. The memory that an index build consumes (see [`maxIndexBuildMemoryUsageMegabytes`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.maxIndexBuildMemoryUsageMegabytes)) is separate from the WiredTiger cache memory. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#wiredtiger-options)
- Enables or disables [prefix compression](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-prefix-compression) for index data. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#wiredtiger-options)
- Specify `true` for [`--wiredTigerIndexPrefixCompression`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--wiredTigerIndexPrefixCompression) to enable [prefix compression](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-prefix-compression) for index data, or `false` to disable prefix compression for index data. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#wiredtiger-options)
- The [`--wiredTigerIndexPrefixCompression`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--wiredTigerIndexPrefixCompression) setting affects all indexes created. If you change the value of [`--wiredTigerIndexPrefixCompression`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--wiredTigerIndexPrefixCompression) on an existing MongoDB deployment, all new indexes use prefix compression. Existing indexes are not affected. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#wiredtiger-options)
- WiredTiger uses [prefix compression](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-prefix-compression) on all indexes by default. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#compression)
- You must specify the `key` field for `$geoNear` on a time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#geonear)
- Starting in MongoDB 7.0, you can use the [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) aggregation stage to write documents to a time series collection. For more information, see [Migrate Data into a Time Series Collection.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-data-into-timeseries-collection.md#std-label-migrate-data-into-a-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#out)
- - Fill gaps in time series data. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#definition)
- The following command runs `$collStats` with the `storageStats: {}` option on a `weather` time series collection using the [WiredTiger Storage Engine](https://www.mongodb.com/docs/manual/core/wiredtiger.md#std-label-storage-wiredtiger), and filters for only time series data: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats.md#storagestats-on-time-series-collections)
- - Data is high volume, since each individual time series requires a large, constantly growing number of documents. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#properties-of-time-series-data)
- - Reduced complexity for working with time series data — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#properties-of-time-series-data)
- Configure, create, and query a time series collection with MongoDB Atlas or a self-managed deployment. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- As you work with time series code examples, add them between the `// start example code here` and `// end example code here` comments. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- This exercise uses [stock ticker sample data](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md#std-label-ts-quick-start-sample-data). The `date` field stores time data, and the `ticker` field identifies the individual stock. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- This creates a reference to an empty "timeseries" database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 6. Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- This creates an empty time series collection named `stocks`. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- You query a time series collection like any other MongoDB collection. For more information, see [About Querying Time Series Data.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#std-label-timeseries-querying) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 7) Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 6) Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 7. Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- This creates and switches to an empty "timeseries" database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 5. Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- ```javascript const timeSeriesDB = client.db('timeseries'); — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- 5) Create an empty time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- As you work with time series code examples, add them between the `# start example code here` and `# end example code here` comments. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- ```python timeseries_db = client["timeseries"] — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- ```python timeseries_db.create_collection("stocks", timeseries=time_series_options) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- - To migrate existing data into a time series collection, see [Migrate Data into a Time Series Collection.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-data-into-timeseries-collection.md#std-label-migrate-data-into-a-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md#next-steps)
- - To learn how MongoDB stores time series data internally, see [About Time Series Data.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucketing) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md#learn-more)
- 2. Create your time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- Before you can output data to a time series collection, you must create the collection with the appropriate options. In this example, we create a `TimeSeriesOptions` object to define the time series options for the new collection, and then create the collection using those options: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- Then, add an [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) aggregation stage to your pipeline that outputs to the new time series collection. Create the output, and then concatenate it to your existing aggregation pipeline: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- For a full explanation of the time series options, see the [Time Series Field Reference.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#std-label-time-series-fields) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- After you run this aggregation pipeline, you can use the standard MongoDB query methods to review the data in your new time series collection. The following example shows how to use the `Find` and `ToList` methods to view a document in your `weather_new` time series collection: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- 2) Create your time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- - Uses [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) with the `timeseries` option to create a `weather_new` time series collection in the `mydatabase` database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- For the aggregation stage syntax, see [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out). For a full explanation of the time series options, see the [Time Series Field Reference.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#std-label-time-series-fields) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- After you run this aggregation pipeline, you can use `find().first()` method to view a document in your `weather_new` time series collection: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- After you run this aggregation pipeline, you can use [`findOne()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.findone.md#mongodb-method-db.collection.findOne) to view a document in your `weather_new` time series collection: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- After you run this aggregation pipeline, you can use `findOne()` method to view a document in your `weather_new` time series collection: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- After you run this aggregation pipeline, you can use `find_one()` method to view a document in your `weather_new` time series collection: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- - Starting in MongoDB 7.0.3 and 7.1, `$out` can take a document to output to a [time series collection:](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#syntax)
- If specified collection exists and the `$out` operation specifies `timeseries` options, then the following restrictions apply: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#replace-existing-collection)
- 1. The existing collection must be a time series collection. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#replace-existing-collection)
- 3. The `timeseries` options included in the `$out` stage must exactly match those on the existing collection. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#replace-existing-collection)
- 1. Create a new time series collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- ```javascript mongodump --uri="mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/weather" \ --collection=temporarytimeseries --out=timeseries ``` — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- ```javascript 2021-06-01T16:48:39.980+0200 writing weather.temporarytimeseries to timeseries/weather/temporarytimeseries.bson 2021-06-01T16:48:40.056+0200 done dumping weather.temporarytimeseries (10000 documents) ``` — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- The following operation imports `timeseries/weather/temporarytimeseries.bson` into the new collection `weathernew`: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- ```javascript mongorestore --uri="mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/weather" \ --collection=weathernew --noIndexRestore \ --maintainInsertionOrder \ timeseries/weather/temporarytimeseries.bson ``` — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- - Analysis of complex time series information without exporting the data to an external database. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md#definition)
- For an additional example about IOT (Internet of Things) Power Consumption, see the [Practical MongoDB Aggregations](https://www.practical-mongodb-aggregations.com/examples/time-series/iot-power-consumption.html) e-book. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md#comparison-with-previous-values-example)
- By default, MongoDB clusters time series collections based on bucket time. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-index.md#clustered-collection)
- A document that reports metrics related to the [internal storage of time series collections.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#std-label-timeseries-bucket-catalog) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#bucketcatalog)
- You can also use the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collstats.md#mongodb-pipeline-pipe.-collStats) aggregation pipeline stage to find time series metrics. To learn more, see [storageStats Output on Time Series Collections.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collstats.md#std-label-storage-stats-time-series) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#bucketcatalog)
- The total number of time series collections. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#catalogstats)
- Once all documents in a bucket are expired, the background task that removes expired buckets removes the bucket during the next run. See [Timing of Delete Operations](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#std-label-timeseries-collection-delete-operations-timing) for more information. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md)
- The document would expire from the database at `"2021-05-19T10:00:00.000Z"`. Once all documents in a bucket are expired, the background task that removes expired buckets removes the bucket during the next run. See [Timing of Delete Operations](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#std-label-timeseries-collection-delete-operations-timing) for more information. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal.md#disable-automatic-removal)
- For efficient time series data storage, MongoDB provides time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md)
- You can [create time series collections in the UI](https://www.mongodb.com/docs/atlas/atlas-ui/collections.md#std-label-atlas-ui-create-a-collection) for deployments hosted in [MongoDB Atlas.](https://www.mongodb.com/docs/atlas) — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#time-series-collections)
- Time series collections generally behave like other MongoDB collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#behavior)
- You can only create time series collections on a system with [featureCompatibilityVersion](https://www.mongodb.com/docs/manual/reference/command/setfeaturecompatibilityversion.md#std-label-view-fcv) set to 5.0 or greater. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md)
- The steps below outline how to effectively configure a time series collection's settings. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#create-a-time-series-collection)
- You query a time series collection the same way you query a standard MongoDB collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-procedures.md#query-a-time-series-collection)
- The query was issued on a timeseries collection. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- $queryStats does not collect query shape statistics for update operations on time series collections. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- $queryStats does not collect query shape statistics for insert operations on time series collections. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- $queryStats does not collect query shape statistics for delete operations on time series collections. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- If your collection stores data that you want to compare across time intervals, use a time series collection to improve performance and storage. For more information on the benefits of time series collections, see [Time Series Collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-data-into-timeseries-collection.md)
- You can create time series collections in the UI for deployments hosted in MongoDB Atlas. — [source](https://www.mongodb.com/docs/manual/core/timeseries-collections/)
- `$queryStats` does not collect query shape statistics for `update` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#update-command-query-shape)
- `$queryStats` does not collect query shape statistics for `insert` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#insert-command-query-shape)
- `$queryStats` does not collect query shape statistics for `delete` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#delete-command-query-shape)
- | Number | Description | | --- | --- | | 0 | Generic binary subtype | | 1 | Function data | | 2 | Binary (old) | | 3 | UUID (old) | | 4 | UUID | | 5 | MD5 | | 6 | Encrypted BSON value | | 7 | Compressed time series data **New in version 5.2** | | 8 | Sensitive data, such as a key or secret. MongoDB does not log literal values for binary data with subtype 8. Instead, MongoDB logs a placeholder value of `###`. | | 9 | Vector data, which is densely packed arrays of numbers of the same type. | | 128 | Custom data | — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert.md#binary-subtypes)
- Comparing Time Series Collections to Regular Collections — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing/)
- You can output a list of collections in a database and filter the results by a variety of properties, including collection type. You can use this functionality to list all time series collections in a database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-check-type.md)
- - `options: { timeseries: { ... } }` — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-check-type.md#output)
- You can use [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) to move data from a time series collection to another collection. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#aggregation-merge)
- Starting in MongoDB 8.0.10, you can reshard a time series collection. All shards in the time series collection must run version 8.0.10 or later to reshard. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#resharding)
- MongoDB supports reads from time series collections in transactions. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#transactions)
- If an embedded data model supports your application's needs, use nested fields. The behavior of nested fields does not differ between regular collections and time series collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices/)
- General indexing strategies also apply to time series collections. For more information, see Indexing Strategies. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices/)
- - Queryable Encryption does not support [Views](https://www.mongodb.com/docs/manual/core/views.md#std-label-views-landing-page), [Time Series Collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), or [capped collection.](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection) — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/limitations.md#collections)
- The `expireAfterSeconds` option is only available for [time series collections](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing) and [clustered collections.](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) — [source](https://www.mongodb.com/docs/manual/tutorial/expire-data.md#specify-expiration-at-collection-creation)
- - Shards an existing time series collection named `deliverySensor` on the `test` database. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#shard-an-existing-time-series-collection)
- - [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc): Returns a date that has been truncated to the specific unit. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#frequently-used-operations)
- - Uses [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) to truncate each document's `date` to the appropriate month. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-aggregations-operators.md#calculate-average-price-per-month)
- Together, [binSize](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-binSize) and [unit](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-unit) specify the time period used in the [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) calculation. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - Divides the time for the [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) calculation into [binSize](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-binSize) time periods in the specified time [unit.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-unit) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - A string other than `week`, [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) uses a reference date of `2000-01-01T00:00:00.00Z`. For example, if [binSize](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-binSize) is `10` and [unit](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-unit) is `year`, example time periods are: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - Equal to `week`, [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) uses a reference date that is set to the earliest first day of the week that is greater than or equal to `2000-01-01`. The first day is set using [startOfWeek](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-startOfWeek) (the default is Sunday). — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `year`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of January 1 for the year in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `quarter`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of the first day of the calendar quarter in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `month`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of the first day of the month in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `day`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of the day in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `hour`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of the hour in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `minute`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for the start of the minute in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - `second`: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) returns the [ISODate](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate) for start of the second in [date.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-date) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#binsize-and-unit-fields)
- - Specified: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) uses [startOfWeek](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-startOfWeek) as the first day of the week for the calculation. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#unit-and-startofweek-fields)
- - Omitted: [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) uses Sunday as the start of the week for the calculation. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#unit-and-startofweek-fields)
- This example uses [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) in a [`$project`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/project.md#mongodb-pipeline-pipe.-project) stage to truncate the cake sales `orderDate` values to two weeks: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#truncate-order-dates-in-a-project-pipeline-stage)
- This example uses [`$dateTrunc`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#mongodb-expression-exp.-dateTrunc) in a [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group) stage to truncate the cake sales `orderDate` values to six months and return the sum of the `quantity` values: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#truncate-order-dates-and-obtain-quantity-sum-in-a-group-pipeline-stage)
- - `$dateTrunc` truncates the `orderDate` field to a `6` [binSize](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-binSize) `month` [unit](https://www.mongodb.com/docs/manual/reference/operator/aggregation/datetrunc.md#std-label-dateTrunc-unit) time period. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc.md#truncate-order-dates-and-obtain-quantity-sum-in-a-group-pipeline-stage)
- The last point is always implicitly connected to the first. You can specify as many points, i.e. sides, as you like. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/polygon.md#definition)

## Related concepts

- index — is a related of MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts
- time series query — is a part of MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts
- working set for time series — is a measure of MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts
- block processing — is a part of MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts
- time series sharding — is a related of MongoDB time-series query execution: bucket unpacking, pushdown, block processing and sorts
