liveBook · Manning

Time-series collection

As explained in MongoDB 8.0 in Action, Third Edition

A time-series collection is a MongoDB collection optimized for storing and querying measurements associated with time values.

A time-series collection is a MongoDB collection for measurements associated with timestamps. Use one when time is central to storing and analyzing data such as sensor readings, server logs, or application performance metrics. section 2.6.3

Compared with a regular collection, it can improve query performance and reduce disk use. MongoDB groups related readings into BSON buckets by time interval and metadata, keeping data points from the same period close together. This reduces I/O when reading time-based data. Simple, flat data models make the most efficient use of the structure. section 2.6.3

To create and inspect one:

  • Create a collection with db.createCollection(), setting timeseries.timeField to the timestamp field and timeseries.metaField to the field that labels a series. section 2.6.3
  • List time-series collections with db.runCommand({ listCollections: 1, filter: { type: "timeseries" } }). section 2.6.3
Listing 2.4 Creating a time-series collection
db.createCollection(
"my_time_series_collection",
{
  timeseries: {
  timeField: "timestamp",
  metaField: "metadata"
}})

This creation command names the timestamp and metadata fields explicitly. section 2.6.3

Choose the metadata field for an identifier that rarely changes, such as the label distinguishing one measurement series from another. Once stored, timestamped data can be queried and aggregated for time-series analysis. section 2.6.3 section 1.5

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains time-and-metadata bucketing and gives creation and inspection commands, but does not work through a measurement query.
Examples
Uses sensor readings, stock prices, logs, and performance metrics, plus commands to create and list time-series collections.
What it assumes
Introduces the collection alongside MongoDB database and document basics and initial Atlas CLI and mongosh work.
What you can do after
Operate/configure it with MongoDB shell commands to create a time-series collection and list collections of that type.
How it connects
Connects time-series collections to BSON, metadata, secondary indexes, and time-series aggregation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.