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.
Important
Feature Compatibility Version Requirement
You can only create time series collections on a system with featureCompatibilityVersion set to 5.0 or greater.
Create a Time Series Collection
Time Series Field Reference
A time series collection includes the following fields:
Field | Type | Description |
|---|---|---|
| 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 |
| 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 Although the |
| integer | Optional. Do not use if setting Possible values are Set For more information on granularity and bucket intervals, see Set Granularity for Time Series Data. |
| integer | Optional. Use with Possible values are 1-31536000. New in version 6.3. |
| integer | Optional. Use with 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. New in version 6.3. |
| integer | Optional. Enable the automatic deletion of documents in a time series collection by specifying the number of seconds after which documents expire. MongoDB deletes expired documents automatically. See Set up Automatic Removal for Time Series Collections (TTL) for more information. |
Other allowed options that are not specific to time series collections are:
storageEngineindexOptionDefaultscollationwriteConcerncomment