@@ -206,6 +206,15 @@ If you specify write concern in both the
206
206
:option:`--writeConcern <mongorestore --writeConcern>` value overrides
207
207
the write concern specified in the URI string.
208
208
209
+ .. _mongorestore-time-series-collections:
210
+
211
+ Time Series Collections
212
+ ~~~~~~~~~~~~~~~~~~~~~~~
213
+
214
+ Starting in MongoDB 5.0, you can use ``mongorestore`` to restore
215
+ :ref:`timeseries collections <manual-timeseries-landing>`.
216
+ For details, see :ref:`mongorestore-example-time-series`.
217
+
209
218
.. _mongorestore-required-access:
210
219
211
220
Required Access
@@ -1245,6 +1254,71 @@ the filename. For example:
1245
1254
1246
1255
mongodump --archive --db=test --port=27017 | mongorestore --archive --port=27018
1247
1256
1257
+
1258
+ .. _mongorestore-example-time-series:
1259
+
1260
+ Restore a Time Series Collection
1261
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1262
+
1263
+ Use ``mongosh`` to create a time series collection. This example
1264
+ uses the default ``test`` database:
1265
+
1266
+ .. code-block:: javascript
1267
+
1268
+ db.createCollection(
1269
+ "weather",
1270
+ {
1271
+ timeseries: {
1272
+ timeField: "timestamp",
1273
+ metaField: "metadata",
1274
+ granularity: "hours"
1275
+ }
1276
+ }
1277
+ )
1278
+
1279
+ Insert time series documents into the collection:
1280
+
1281
+ .. code-block:: javascript
1282
+
1283
+ db.weather.insertMany( [
1284
+ {
1285
+ "metadata": { "sensorId": 5578, "type": "temperature" },
1286
+ "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
1287
+ "temp": 12
1288
+ },
1289
+ {
1290
+ "metadata": { "sensorId": 5578, "type": "temperature" },
1291
+ "timestamp": ISODate("2021-05-18T04:00:00.000Z"),
1292
+ "temp": 11
1293
+ },
1294
+ {
1295
+ "metadata": { "sensorId": 5578, "type": "temperature" },
1296
+ "timestamp": ISODate("2021-05-18T08:00:00.000Z"),
1297
+ "temp": 11
1298
+ }
1299
+ ] )
1300
+
1301
+ From your terminal, use ``mongodump`` to export the time series collection
1302
+ to the ``dump/test`` directory. This command adds two files
1303
+ ``system.buckets.weather.bson`` and ``weather.metadata.json`` to
1304
+ the directory:
1305
+
1306
+ .. code-block:: sh
1307
+
1308
+ mongodump --db=test
1309
+
1310
+ Use ``mongorestore`` to restore the data to the ``mongorestore.weather``
1311
+ namespace:
1312
+
1313
+ .. code-block:: sh
1314
+
1315
+ mongorestore --host localhost --port 27017 --nsFrom='test.*' --nsTo='mongorestore.*' dump/
1316
+
1317
+ .. note::
1318
+
1319
+ You cannot restore the ``system.buckets.weather.bson`` file
1320
+ by itself. Attempting to do so results in an error.
1321
+
1248
1322
.. _mongorestore-example-connect-using-aws-iam:
1249
1323
1250
1324
Connect to a MongoDB Atlas Cluster using AWS IAM Credentials
0 commit comments