Skip to content

Commit d094c77

Browse files
authored
DOCSP-38307: Add time series collections page (#200)
1 parent 7412c9e commit d094c77

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

source/fundamentals.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fundamentals
2323
/fundamentals/specify-query
2424
/fundamentals/serialization
2525
/fundamentals/logging
26+
/fundamentals/time-series
2627
/fundamentals/encrypt-fields
2728

2829
- :ref:`Connecting to MongoDB <csharp-connection>`
@@ -37,4 +38,5 @@ Fundamentals
3738
- :ref:`csharp-specify-query`
3839
- :ref:`csharp-serialization`
3940
- :ref:`csharp-logging`
41+
- :ref:`csharp-time-series`
4042
- :ref:`Encrypt Fields <csharp-fle>`

source/fundamentals/time-series.txt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
.. _csharp-time-series:
2+
3+
=======================
4+
Time Series Collections
5+
=======================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
16+
In this guide, you can learn how to use and interact with **time series collections** in
17+
MongoDB using the {+driver-long+}.
18+
19+
Time series collections efficiently store sequences of measurements over
20+
a period of time. Time series data consists of any data collected over
21+
time, metadata that describes the measurement, and the time of the
22+
measurement.
23+
24+
.. list-table::
25+
:widths: 33, 33, 33
26+
:header-rows: 1
27+
:stub-columns: 1
28+
29+
* - Example
30+
- Measurement
31+
- Metadata
32+
33+
* - Sales Data
34+
- Revenue
35+
- Company
36+
37+
* - Infection Rates
38+
- Amount of People Infected
39+
- Location
40+
41+
Create a Time Series Collection
42+
-------------------------------
43+
44+
.. important::
45+
46+
Time series collections require MongoDB 5.0 or later.
47+
48+
To create a time series collection, pass the following parameters to the
49+
``CreateCollection()`` method:
50+
51+
- Name of the new collection to create
52+
- ``CreateCollectionOptions`` object that contains a ``TimeSeriesOptions`` object
53+
54+
.. literalinclude:: /includes/fundamentals/code-examples/TimeSeries.cs
55+
:start-after: begin-time-series
56+
:end-before: end-time-series
57+
:language: csharp
58+
:dedent:
59+
60+
To check if you successfully created the collection, send the
61+
``"listCollections"`` command to the ``RunCommand()`` method as shown in the following
62+
example:
63+
64+
.. literalinclude:: /includes/fundamentals/code-examples/TimeSeries.cs
65+
:start-after: begin-run-command
66+
:end-before: end-run-command
67+
:language: csharp
68+
:dedent:
69+
70+
Your output will look similar to the following:
71+
72+
.. code-block:: json
73+
74+
{
75+
"cursor":{
76+
...
77+
"firstBatch":[
78+
{
79+
"name":"september2021",
80+
"type":"timeseries",
81+
"options":{
82+
"timeseries":{
83+
...
84+
}
85+
},
86+
"info":{
87+
"readOnly":false
88+
}
89+
},
90+
...
91+
}
92+
93+
Query a Time Series Collection
94+
------------------------------
95+
96+
To query a time series collection, follow the conventions for retrieving and aggregating
97+
data. For more information about these conventions, see the :ref:`csharp-retrieve` guide.
98+
99+
Additional Information
100+
----------------------
101+
102+
To learn more about the operations mentioned on this page, see the following
103+
Server manual guides:
104+
105+
- :ref:`manual-timeseries-collection`
106+
- :ref:`manual-timeseries-collection-limitations`
107+
108+
API Documentation
109+
~~~~~~~~~~~~~~~~~
110+
111+
To learn more about any of the methods or types discussed in this
112+
guide, see the following API documentation:
113+
114+
- `CreateCollection() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.CreateCollection.html>`__
115+
- `CreateCollectionOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CreateCollectionOptions.html>`__
116+
- `TimeSeriesOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.TimeSeriesOptions.html>`__
117+
- `RunCommand() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.RunCommand.html>`__
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using MongoDB.Bson;
2+
using MongoDB.Bson.Serialization.Attributes;
3+
using MongoDB.Bson.Serialization.Conventions;
4+
using MongoDB.Driver;
5+
6+
public class TimeSeries
7+
{
8+
// Replace with your connection string
9+
private const string MongoConnectionString = "<YOUR_CONNECTION_STRING>";
10+
11+
public static void Main(string[] args)
12+
{
13+
var mongoClient = new MongoClient(MongoConnectionString);
14+
15+
// begin-time-series
16+
var database = mongoClient.GetDatabase("fall_weather");
17+
var tsOptions = new TimeSeriesOptions("temperature");
18+
19+
// Creates a time series collection that stores "temperature" values over time
20+
var collOptions = new CreateCollectionOptions { TimeSeriesOptions = tsOptions };
21+
database.CreateCollection("september2021", collOptions);
22+
// end-time-series
23+
24+
// begin-run-command
25+
var commandResult = database.RunCommand<BsonDocument>(new BsonDocument("listCollections", 1 ));
26+
Console.WriteLine(commandResult.ToJson());
27+
// end-run-command
28+
}
29+
30+
}

0 commit comments

Comments
 (0)