Skip to content

Commit 37d1680

Browse files
jeff-allen-mongoJocelyn Mendez
andauthored
Time series updates for sharding support and updates / deletes (#6085)
* DOCSP-16551 updates and deletes limitations on time-series collections * (DOCSP-18792): Sharding support for time series collections * copy tweaks * updates per Arun's feedback * Updates per review part 2 Co-authored-by: Jocelyn Mendez <[email protected]>
1 parent 459754f commit 37d1680

12 files changed

+182
-41
lines changed

source/core/timeseries-collections.txt

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ command:
7979
}
8080
)
8181

82+
.. _time-series-fields:
83+
8284
When creating a time series collection, specify the following options:
8385

8486
.. list-table::
@@ -95,44 +97,19 @@ When creating a time series collection, specify the following options:
9597

9698
- string
9799

98-
- Required. The name of the field which contains the date in each
99-
time series document. Documents in a time series collection must
100-
have a valid BSON date as the value for the ``timeField``.
100+
- .. include:: /includes/time-series/fact-time-field-description.rst
101101

102102
* - ``timeseries.metaField``
103103

104104
- string
105105

106-
- Optional. The name of the field which contains metadata in each
107-
time series document. The metadata in the specified field should
108-
be data that is used to label a unique series of documents. The
109-
metadata should rarely, if ever, change.
110-
111-
The name of the specified field may not be ``_id`` or the same as
112-
the ``timeseries.timeField``. The field can be of any type.
106+
- .. include:: /includes/time-series/fact-meta-field-description.rst
113107

114108
* - ``timeseries.granularity``
115109

116110
- string
117111

118-
- Optional. Possible values are ``"seconds"``, ``"minutes"``, and
119-
``"hours"``. By default, MongoDB sets the ``granularity`` to
120-
``"seconds"`` for high-frequency ingestion.
121-
122-
Manually set the ``granularity`` parameter to improve performance
123-
by optimizing how data in the time series collection is stored
124-
internally. To select a value for ``granularity``, choose the
125-
closest match to the time span between consecutive incoming
126-
measurements.
127-
128-
If you specify the ``timeseries.metaField``, consider the time
129-
span between consecutive incoming measurements that have the same
130-
unique value for the ``metaField`` field. Measurements often have
131-
the same unique value for the ``metaField`` field if they come
132-
from the same source.
133-
134-
If you do not specify ``timeseries.metaField``, consider the time
135-
span between all measurements that are inserted in the collection.
112+
- .. include:: /includes/time-series/fact-granularity-description.rst
136113

137114
* - ``expireAfterSeconds``
138115

source/core/timeseries/timeseries-granularity.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,8 @@ a time. From ``"seconds"`` to ``"minutes"`` or from ``"minutes"`` to
143143
``"hours"``. Other changes are not allowed. If you need to change the
144144
``granularity`` from ``"seconds"`` to ``"hours"``, first increase the
145145
``granularity`` to ``"minutes"`` and then to ``"hours"``.
146+
147+
.. note::
148+
149+
You cannot modify the ``granularity`` of a sharded time series
150+
collection.

source/core/timeseries/timeseries-limitations.txt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ Constraints
2121

2222
The maximum size of a measurement document is 4 MB.
2323

24+
.. _timeseries-limitations-updates-deletes:
25+
2426
Updates and Deletes
2527
~~~~~~~~~~~~~~~~~~~
2628

27-
:ref:`Time series collections <manual-timeseries-collection>` only
28-
support insert operations and read queries. Updates and manual delete operations
29-
result in an error.
29+
:ref:`Time series collections <manual-timeseries-collection>` support update
30+
and delete operations with limitations. The following operations are not supported
31+
on time series collections:
32+
33+
- :dbcommand:`findAndModify`.
34+
- Updates that modify the ``timeField``.
35+
- Updates with ``multi:false`` that modify the ``metaField``.
36+
- Updates with ``upsert:true``.
37+
- Updates or deletes in multi-document transactions.
38+
39+
MongoDB supports all other update and delete operations. For more information,
40+
see :ref:`<collection-method>`.
3041

3142
To automatically delete old data, :ref:`set up automatic removal (TTL)
3243
<set-up-automatic-removal>`.
@@ -117,11 +128,21 @@ Client-Side Field Level Encryption
117128
</core/security-client-side-encryption>` is not supported for
118129
:ref:`time series collections <manual-timeseries-collection>`.
119130

131+
.. _time-series-limitations-sharding:
132+
120133
Sharding
121134
~~~~~~~~
122135

123-
:ref:`Time series collections <manual-timeseries-collection>` cannot
124-
currently be sharded.
136+
Starting in MongoDB 5.1, sharded time series collections are supported.
137+
When using sharded time series collections, you cannot:
138+
139+
- Modify the ``granularity`` of a sharded time series
140+
collection.
141+
142+
- Run sharding administration commands, including:
143+
144+
- :dbcommand:`moveChunk`
145+
- :dbcommand:`splitChunk`
125146

126147
Aggregation $out and $merge
127148
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MongoDB 5.1 provides support for sharded :ref:`time series collections
2+
<manual-timeseries-collection>`.
3+
4+
See:
5+
6+
- :dbcommand:`shardCollection`
7+
- :ref:`Time Series Limitations <time-series-limitations-sharding>`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Optional. Possible values are:
2+
3+
- ``"seconds"``
4+
- ``"minutes"``
5+
- ``"hours"``
6+
7+
By default, MongoDB sets the ``granularity`` to ``"seconds"`` for
8+
high-frequency ingestion.
9+
10+
Manually set the ``granularity`` parameter to improve performance
11+
by optimizing how data in the time series collection is stored
12+
internally. To select a value for ``granularity``, choose the
13+
closest match to the time span between consecutive incoming
14+
measurements.
15+
16+
If you specify the ``timeseries.metaField``, consider the time
17+
span between consecutive incoming measurements that have the same
18+
unique value for the ``metaField`` field. Measurements often have
19+
the same unique value for the ``metaField`` field if they come
20+
from the same source.
21+
22+
If you do not specify ``timeseries.metaField``, consider the time
23+
span between all measurements that are inserted in the collection.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Optional. The name of the field which contains metadata in each
2+
time series document. The metadata in the specified field should
3+
be data that is used to label a unique series of documents. The
4+
metadata should rarely, if ever, change.
5+
6+
The name of the specified field may not be ``_id`` or the same as
7+
the ``timeseries.timeField``. The field can be of any type.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Required. The name of the field which contains the date in each
2+
time series document. Documents in a time series collection must
3+
have a valid BSON date as the value for the ``timeField``.

source/reference/command/findAndModify.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _find-and-modify:
2+
13
=============
24
findAndModify
35
=============

source/reference/command/shardCollection.txt

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Definition
3535
unique: <boolean>,
3636
numInitialChunks: <integer>,
3737
presplitHashedZones: <boolean>,
38-
collation: { locale: "simple" }
38+
collation: { locale: "simple" },
39+
timeseries: <object>
3940
}
4041

4142
:dbcommand:`shardCollection` has the following fields:
@@ -170,6 +171,64 @@ Definition
170171

171172
.. versionadded:: 4.4
172173

174+
* - :ref:`timeseries <cmd-shard-collection-timeseries>`
175+
176+
- object
177+
178+
- .. _cmd-shard-collection-timeseries:
179+
180+
Optional. Specify this option to create a new sharded
181+
:ref:`time series collection <manual-timeseries-collection>`.
182+
183+
To shard an existing time series collection, omit this
184+
parameter. When you omit this parameter and specify a time
185+
series collection in the ``shardCollection`` parameter,
186+
MongoDB automatically uses the values from the time series
187+
collection as the values for the ``timeseries`` field.
188+
189+
For detailed syntax, see
190+
:ref:`sharded-time-series-collection-options`.
191+
192+
.. versionadded:: 5.1
193+
194+
.. _sharded-time-series-collection-options:
195+
196+
Time Series Options
197+
~~~~~~~~~~~~~~~~~~~
198+
199+
.. versionadded:: 5.1
200+
201+
Specify the :ref:`timeseries <cmd-shard-collection-timeseries>` option
202+
to :dbcommand:`shardCollection` to create a new sharded
203+
:ref:`time series collection <manual-timeseries-collection>`.
204+
205+
The :ref:`timeseries <cmd-shard-collection-timeseries>` option takes
206+
the following fields:
207+
208+
.. list-table::
209+
:header-rows: 1
210+
:widths: 20 20 80
211+
212+
* - Field
213+
- Type
214+
- Description
215+
216+
* - ``timeField``
217+
- string
218+
- .. include:: /includes/time-series/fact-time-field-description.rst
219+
220+
* - ``metaField``
221+
- string
222+
- .. include:: /includes/time-series/fact-meta-field-description.rst
223+
224+
* - ``granularity``
225+
- string
226+
- .. include:: /includes/time-series/fact-granularity-description.rst
227+
228+
* - ``bucketMaxSpanSeconds``
229+
- integer
230+
- Optional. The maximum range of time values for a bucket,
231+
in seconds.
173232

174233
Considerations
175234
--------------
@@ -194,6 +253,21 @@ avoid scalability and perfomance issues.
194253
- :ref:`sharding-shard-key-selection`
195254
- :ref:`sharding-shard-key`
196255

256+
Shard Keys on Time Series Collections
257+
`````````````````````````````````````
258+
259+
When sharding time series collections, you can only specify the
260+
``metaField`` (or sub-fields of ``metaField``), ``timeField``, or both
261+
in the shard key. No other fields, including ``_id``, are allowed in the
262+
shard key pattern.
263+
264+
- ``metaField`` can be either a :ref:`hashed shard key
265+
<sharding-hashed-sharding>` or a :ref:`ranged shard key
266+
<sharding-ranged>`.
267+
268+
- ``timeField`` can only be a :ref:`ranged shard key
269+
<sharding-ranged>` and must be at the end of the shard key pattern.
270+
197271
.. _hashed-shard-keys:
198272

199273
Hashed Shard Keys
@@ -274,6 +348,7 @@ in the ``records`` database and uses the ``zipcode`` field as the
274348
.. code-block:: javascript
275349

276350
db.adminCommand( { shardCollection: "records.people", key: { zipcode: 1 } } )
351+
277352

278353
.. seealso::
279354

source/reference/method/db.collection.update.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _collection-update:
2+
13
======================
24
db.collection.update()
35
======================
@@ -51,6 +53,8 @@ The :method:`db.collection.update()` method has the following form:
5153
}
5254
)
5355

56+
.. _update-parameters:
57+
5458
Parameters
5559
~~~~~~~~~~
5660

0 commit comments

Comments
 (0)