@@ -4,6 +4,9 @@ Best Practices for Time Series Collections
4
4
5
5
.. default-domain:: mongodb
6
6
7
+ .. meta::
8
+ :keywords: Time series, Best practices
9
+
7
10
.. contents:: On this page
8
11
:local:
9
12
:backlinks: none
@@ -21,25 +24,27 @@ Optimize Inserts
21
24
To optimize insert performance for time series collections, perform the
22
25
following actions.
23
26
24
- Batch Documents by Metadata
25
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
+ Batch Document Writes
28
+ ~~~~~~~~~~~~~~~~~~~~~
26
29
27
30
When inserting multiple documents:
28
31
29
32
- To avoid network roundtrips, use a single
30
33
:method:`~db.collection.insertMany()` statement as opposed to
31
34
multiple :method:`~db.collection.insertOne()` statements.
32
35
33
- - If possible, order or construct batches to contain multiple
34
- measurements per series (as defined by metadata).
36
+ - If possible, construct batches to contain multiple measurements per series
37
+ (as defined by metadata).
38
+
39
+ - To improve performance, set the ``ordered`` parameter to ``false``.
35
40
36
41
For example, if you have two sensors, ``sensor A`` and ``sensor B``, a
37
42
batch containing multiple measurements from a single sensor incurs the
38
43
cost of one insert, rather than one insert per measurement.
39
44
40
45
The following operation inserts six documents, but only incurs the cost
41
46
of two inserts (one per batch), because the documents are ordered by
42
- sensor:
47
+ sensor. The ``ordered`` parameter is set to ``false`` to improve performance :
43
48
44
49
.. code-block:: javascript
45
50
@@ -86,7 +91,9 @@ sensor:
86
91
"timestamp": ISODate("2021-05-20T00:00:00.000Z"),
87
92
"temperature": 26
88
93
}
89
- ] )
94
+ ], {
95
+ "ordered": false
96
+ })
90
97
91
98
Use Consistent Field Order in Documents
92
99
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments