|
| 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>`__ |
0 commit comments