In this guide, you can learn how to use and interact with time series collections in MongoDB using the MongoDB .NET/C# Driver.
Time series collections efficiently store sequences of measurements over a period of time. Time series data consists of any data collected over time, metadata that describes the measurement, and the time of the measurement.
Example
Measurement
Metadata
Sales Data
Revenue
Company
Infection Rates
Amount of People Infected
Location
ImportantTime series collections require MongoDB 5.0 or later.
To create a time series collection, pass the following parameters to the CreateCollection()
method:
Name of the new collection to create
CreateCollectionOptions
object that contains a TimeSeriesOptions
object
var database = mongoClient.GetDatabase("fall_weather");var tsOptions = new TimeSeriesOptions("temperature");var collOptions = new CreateCollectionOptions { TimeSeriesOptions = tsOptions };database.CreateCollection("september2021", collOptions);
To check if you successfully created the collection, use the ListCollections()
or ListCollectionsAsync()
method as shown in the following example:
var collections = database.ListCollections().ToList();foreach (var collection in collections) { Console.WriteLine(collection);}
Your output will look similar to the following:
{ "name": "september2021", "type": "timeseries", "options": { "timeseries": { "timeField": "temperature", "granularity": "seconds", "bucketMaxSpanSeconds": 3600 } }, "info": { "readOnly": false }}...
To query a time series collection, follow the conventions for retrieving and aggregating data. For more information about these conventions, see the Retrieve Data and Aggregation Operations guides.
To learn more about the operations mentioned on this page, see the following Server manual guides:
To learn more about any of the methods or types discussed in this guide, see the following API documentation:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4