For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Aggregation and Operator Considerations

Some aggregation stages and operators require special considerations when you use them with time series collections.

Time series collections only support the $geoNear aggregation stage for sorting geospatial data from queries against 2dsphere indexes. You can't use the $near and $nearSphere operators on time series collections.

You can't use the query field for $geoNear on a time series collection.

You must specify the key field for $geoNear on a time series collection.

You cannot use the $merge aggregation stage to add data from another collection to a time series collection.

Starting in MongoDB 7.0, you can use the $out aggregation stage to write documents to a time series collection. For more information, see Migrate Data into a Time Series Collection.

The following aggregation pipeline operators and stages are often used to analyze time series data:

  • $dateAdd: Adds a specified amount of time to a Date object.

  • $dateDiff: Returns the time difference between two dates.

  • $dateTrunc: Returns a date that has been truncated to the specific unit.

  • $setWindowFields: Runs calculations on documents in a given window.