@@ -16,9 +16,8 @@ Set Granularity for Time Series Data
16
16
:description: Time series, granularity, IOT
17
17
:keywords: Time series, granularity, IOT
18
18
19
- When you create a :ref:`time series collection
20
- <manual-timeseries-collection>`, MongoDB automatically creates a
21
- ``system.buckets`` :ref:`system collection
19
+ When you create a time series collection, MongoDB automatically creates
20
+ a ``system.buckets`` :ref:`system collection
22
21
<metadata-system-collections>` and groups incoming time series data
23
22
into buckets. By setting granularity, you control how
24
23
frequently data is bucketed based on the ingestion rate of your data.
@@ -34,7 +33,7 @@ boundaries and more accurately control how time series data is bucketed.
34
33
created. See :ref:`MongoDB 5.0 known issues
35
34
<5.0-known-issue-granularity>`.
36
35
37
- Retrieve the Current bucketing parameters
36
+ Retrieve the Current Bucketing Parameters
38
37
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
38
40
39
To retrieve current collection values, use the
@@ -44,9 +43,8 @@ To retrieve current collection values, use the
44
43
45
44
db.runCommand( { listCollections: 1 } )
46
45
47
- The result document contains a document for the time series collection
48
- which contains ``options.timeseries.granularity``,
49
- ``options.timeseries.bucketMaxSpanSeconds``, and ``options.timeseries.bucketRoundingSeconds`` fields, if present.
46
+ For time series collections, the output contains
47
+ ``granularity``, ``bucketMaxSpanSeconds``, and ``bucketRoundingSeconds`` fields, if present.
50
48
51
49
.. code-block:: javascript
52
50
:copyable: false
@@ -77,8 +75,8 @@ which contains ``options.timeseries.granularity``,
77
75
}
78
76
79
77
80
- Using a Single `` granularity`` Field
81
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
+ Using the " granularity" Field
79
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
80
83
81
The following table shows the maximum time interval included in one
84
82
bucket of data when using a given ``granularity`` value:
@@ -121,13 +119,18 @@ might contain only a single document.
121
119
Using Custom Bucketing Parameters
122
120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
121
124
- Instead of ``granularity``, you can set bucket boundaries manually using
125
- the two custom bucketing parameters. Set both parameters to the
126
- same value, and do not set ``granularity``:
122
+ In MongoDB 6.3 and higher, instead of ``granularity``, you can set
123
+ bucket boundaries manually using the two custom bucketing parameters.
124
+ Consider this approach if you need the additional precision to optimize
125
+ a high volume of queries and :dbcommand:`insert` operations.
127
126
128
- - ``bucketMaxSpanSeconds``, sets the maximum time between timestamps
127
+ To use custom bucketing parameters, set both parameters to the same
128
+ value, and do not set ``granularity``:
129
+
130
+ - ``bucketMaxSpanSeconds`` sets the maximum time between timestamps
129
131
in the same bucket. Possible values are 1-31536000.
130
- - ``bucketRoundingSeconds``, the time interval that determines the
132
+
133
+ - ``bucketRoundingSeconds`` sets the time interval that determines the
131
134
starting timestamp for a new bucket. When a document requires a new
132
135
bucket, MongoDB rounds down the document's timestamp value by this
133
136
interval to set the minimum time for the bucket.
@@ -160,11 +163,6 @@ Change Time Series Granularity
160
163
You can increase ``timeseries.granularity`` from a shorter unit of time
161
164
to a longer one using a :dbcommand:`collMod` command.
162
165
163
- .. note::
164
-
165
- To modify the granularity of a **sharded** time series collection,
166
- you must be running MongoDB 6.0 or later.
167
-
168
166
.. code-block:: javascript
169
167
170
168
db.runCommand({
@@ -187,4 +185,10 @@ command and set them to the same value:
187
185
}
188
186
})
189
187
190
- You cannot decrease the granularity interval or the custom bucketing values.
188
+ You cannot decrease the granularity interval or the custom bucketing
189
+ values.
190
+
191
+ .. note::
192
+
193
+ To modify the granularity of a **sharded** time series collection,
194
+ you must be running MongoDB 6.0 or later.
0 commit comments