Skip to content

Commit c648e95

Browse files
authored
Merge DOCS-15691 to v6.3: Additional timeseries options - bucketMaxSpanSeconds and bucketRoundingSeconds (#2143)
* Changes to granularity and addition of two timeseries options * Add context about bucketing * resolve merge conflict * copy review feedback * copy review 2 * tech review feedback * update release notes
1 parent 5236a94 commit c648e95

File tree

10 files changed

+146
-173
lines changed

10 files changed

+146
-173
lines changed

source/core/timeseries/timeseries-granularity.txt

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ Set Granularity for Time Series Data
2424
<5.0-known-issue-granularity>`.
2525

2626
When you create a :ref:`time series collection
27-
<manual-timeseries-collection>`, set the granularity to the value that
28-
is the closest match to the time span between consecutive incoming
29-
measurements that have the same unique value for the ``metaField``
30-
field:
27+
<manual-timeseries-collection>`, you can specify the
28+
``granularity`` parameter. The ``granularity`` determines how data
29+
in the time series collection is stored internally. For details about
30+
how MongoDB stores time series data, see :ref:`flexible-bucketing`.
31+
32+
By default, ``granularity`` is set to ``"seconds"``. To optimize
33+
data storage, set the ``granularity`` to a value that is closest
34+
to the ingestion rate for your data source as specified by
35+
the ``metaField`` field. The ingestion rate is the time span between
36+
consecutive incoming measurements that have the same unique value for
37+
the ``metaField``.
38+
39+
Consider the following example:
3140

3241
.. code-block:: javascript
3342

@@ -43,19 +52,12 @@ field:
4352
}
4453
)
4554

46-
Setting the ``granularity`` parameter accurately improves performance by
47-
optimizing how data in the time series collection is stored internally.
48-
49-
To set the parameter accurately, choose a ``granularity`` value that is
50-
closest to the ingestion rate for a unique data source as specified by
51-
the value for the ``metaField`` field.
52-
53-
For example, if your ``metaField`` data identifies weather sensors and
55+
If your ``metaField`` data identifies weather sensors and
5456
you ingest data from each individual sensor once every 5 minutes, you
5557
should choose ``"minutes"``. Even if you have thousands of sensors and
5658
the data coming in from different sensors is only seconds apart, the
5759
``granularity`` should still be based on the ingestion rate for one
58-
sensor that is uniquely identified by its metadata.
60+
sensor that is uniquely identified by its metadata.
5961

6062
In the following table, you can see the max time span of data that is
6163
stored together for each ``granularity`` value:
@@ -148,3 +150,57 @@ a time. From ``"seconds"`` to ``"minutes"`` or from ``"minutes"`` to
148150

149151
You cannot modify the ``granularity`` of a sharded time series
150152
collection.
153+
154+
.. _flexible-bucketing:
155+
156+
Flexible Bucketing
157+
~~~~~~~~~~~~~~~~~~
158+
159+
MongoDB groups incoming time series data into buckets. By setting the
160+
``granularity`` parameter, you control how frequently data is bucketed
161+
based on the ingestion rate of your data.
162+
163+
Starting in MongoDB 6.3, you can specify the bucket boundaries to
164+
more accurately control how time series data is bucketed. Use the
165+
following parameters:
166+
167+
- ``bucketMaxSpanSeconds``, the maximum time span between measurements
168+
in a bucket.
169+
- ``bucketRoundingSeconds``, the time interval that determines the
170+
starting timestamp for a new bucket.
171+
172+
.. note::
173+
174+
If you want to specify the bucket boundaries:
175+
176+
- You must set both ``bucketMaxSpanSeconds`` and ``bucketRoundingSeconds``.
177+
- Both parameters must have the same value.
178+
- You can't additionally set the ``granularity`` parameter.
179+
180+
Consider the following time series collection:
181+
182+
.. code-block:: javascript
183+
184+
db. createCollection(
185+
"weather24h",
186+
{
187+
timeseries: {
188+
timeField: "timestamp",
189+
metaField: "metadata",
190+
bucketMaxSpanSeconds: 60,
191+
bucketRoundingSeconds: 60
192+
}
193+
}
194+
)
195+
196+
Each bucket has a maximum time span of 60 seconds. When MongoDB opens a
197+
new bucket, the starting timestamp is rounded down to the nearest 60-second
198+
interval.
199+
200+
For example, if you insert a new measurement into the collection with a
201+
timestamp of ``11:59:59``, the measurement is added to the bucket
202+
with boundaries between ``11:59:00`` and ``12:00:00`` (non-inclusive).
203+
If the bucket doesn't exist, the starting timestamp of the new bucket
204+
is determined by rounding ``11:59:59`` down to ``11:59:00``.
205+
206+
For more information on time series parameters, see :ref:`time-series-fields`.

source/core/timeseries/timeseries-limitations.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ a time. From ``"seconds"`` to ``"minutes"`` or from ``"minutes"`` to
169169
``granularity`` from ``"seconds"`` to ``"hours"``, first increase the
170170
``granularity`` to ``"minutes"`` and then to ``"hours"``.
171171

172+
Modification of Bucket Parameters
173+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174+
175+
Once you set a collection's ``bucketMaxSpanSeconds`` and
176+
``bucketRoundingSeconds`` parameters, they can only be increased. Use
177+
the :dbcommand:`collMod` command to modify the ``bucketMaxSpanSeconds``
178+
and ``bucketRoundingSeconds`` parameters. For example:
179+
180+
.. code-block:: javascript
181+
182+
db.runCommand({
183+
collMod: "timeseries",
184+
timeseries: { bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600 }
185+
})
186+
187+
.. note::
188+
189+
The ``bucketMaxSpanSeconds`` and ``bucketRoundingSeconds`` parameters must be
190+
equal. If you modify one parameter, you must also modify the other.
191+
172192
.. _time-series-limitations-sharding:
173193

174194
Sharding

source/core/timeseries/timeseries-procedures.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,31 @@ When creating a time series collection, specify the following options:
5555
:widths: 40 20 60
5656

5757
* - Field
58-
5958
- Type
60-
6159
- Description
6260

6361
* - ``timeseries.timeField``
64-
6562
- string
66-
6763
- .. include:: /includes/time-series/fact-time-field-description.rst
6864

6965
* - ``timeseries.metaField``
70-
7166
- string
72-
7367
- .. include:: /includes/time-series/fact-meta-field-description.rst
7468

7569
* - ``timeseries.granularity``
76-
7770
- string
78-
7971
- .. include:: /includes/time-series/fact-granularity-description.rst
8072

81-
* - ``expireAfterSeconds``
82-
73+
* - ``timeseries.bucketMaxSpanSeconds``
8374
- number
75+
- .. include:: /includes/time-series/fact-bucket-max-span-description.rst
8476

77+
* - ``timeseries.bucketRoundingSeconds``
78+
- number
79+
- .. include:: /includes/time-series/fact-bucket-rounding-description.rst
80+
81+
* - ``expireAfterSeconds``
82+
- number
8583
- Optional. Enable the automatic deletion of documents in a
8684
:term:`time series collection` by specifying the number of seconds
8785
after which documents expire. MongoDB deletes expired documents
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Optional. The maximum time span between measurements in a bucket.
2+
For more information, see :ref:`flexible-bucketing`.
3+
4+
If you set this parameter:
5+
6+
- ``timeseries.bucketRoundingSeconds`` must have the same value.
7+
- You can't set ``timeseries.granularity``.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Optional. The time interval that determines the starting
2+
timestamp for a new bucket. For more information, see
3+
:ref:`flexible-bucketing`.
4+
5+
If you set this parameter:
6+
7+
- ``timeseries.bucketMaxSpanSeconds`` must have the same value.
8+
- You can't set ``timeseries.granularity``.

source/includes/time-series/fact-granularity-description.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ from the same source.
2121

2222
If you do not specify ``timeseries.metaField``, consider the time
2323
span between all measurements that are inserted in the collection.
24+
25+
If you set the ``granularity`` parameter, you can't set the
26+
``bucketMaxSpanSeconds`` and ``bucketRoundingSeconds`` parameters.

0 commit comments

Comments
 (0)