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








