liveBook · Manning

Time series

As explained in MongoDB 8.0 in Action, Third Edition

Time-series data is a sequence of observations whose values are associated with timestamps and analyzed through changes over time.

Time-series data is a sequence of measurements associated with timestamps, where useful meaning comes from observing how values change over time. Common applications include sensor readings, stock prices, server logs, and application performance metrics. MongoDB time-series collections store related points in time- and metadata-based buckets, improving query performance and reducing disk use compared with regular collections. section 2.6.3

Model each time-series record around three elements:

  • A timestamp records when the data point was captured. section 2.6.3
  • Metadata identifies the series and rarely changes, such as a sensor or other source label. section 2.6.3
  • Measurements contain the values monitored over time, typically as changing key-value pairs. section 2.6.3

MongoDB combines multiple readings into BSON documents within buckets. This reduces storage and read I/O while keeping related observations close together. Nested documents are possible, but simple, flat data models are the most efficient for this structure. section 2.6.3

Creating a MongoDB time-series collection

Define the timestamp field and the metadata field when creating the collection. For example, a collection can use timestamp for observation times and metadata for stable series identifiers; listCollections can then filter for collections whose type is timeseries. section 2.6.3

Listing 2.4 Creating a time-series collection
db.createCollection(
"my_time_series_collection",
{
  timeseries: {
  timeField: "timestamp",
  metaField: "metadata"
}})

Shows the MongoDB createCollection command with timeseries, timeField, and metaField options. section 2.6.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains timestamps, metadata, measurements, bucketed BSON storage, and flat-model guidance without detailing advanced query design.
Examples
Uses sensor readings, stock prices, server logs, application metrics, and a MongoDB collection-creation command.
What you can do after
Operate/configure MongoDB time-series collections by assigning timestamp and metadata fields during creation.
How it connects
Connects time-series collections with MongoDB collections, BSON, buckets, secondary indexes, and query performance.

Also explained in

Compare how 9 books explain time series →

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.