@@ -4,6 +4,9 @@ Best Practices for Time Series Collections
44
55.. default-domain:: mongodb
66
7+ .. meta::
8+ :keywords: Time series, Best practices
9+
710.. contents:: On this page
811 :local:
912 :backlinks: none
@@ -21,25 +24,27 @@ Optimize Inserts
2124To optimize insert performance for time series collections, perform the
2225following actions.
2326
24- Batch Documents by Metadata
25- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+ Batch Document Writes
28+ ~~~~~~~~~~~~~~~~~~~~~
2629
2730When inserting multiple documents:
2831
2932- To avoid network roundtrips, use a single
3033 :method:`~db.collection.insertMany()` statement as opposed to
3134 multiple :method:`~db.collection.insertOne()` statements.
3235
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``.
3540
3641For example, if you have two sensors, ``sensor A`` and ``sensor B``, a
3742batch containing multiple measurements from a single sensor incurs the
3843cost of one insert, rather than one insert per measurement.
3944
4045The following operation inserts six documents, but only incurs the cost
4146of 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 :
4348
4449.. code-block:: javascript
4550
@@ -86,7 +91,9 @@ sensor:
8691 "timestamp": ISODate("2021-05-20T00:00:00.000Z"),
8792 "temperature": 26
8893 }
89- ] )
94+ ], {
95+ "ordered": false
96+ })
9097
9198Use Consistent Field Order in Documents
9299~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments