If your collection stores data that you want to compare across time intervals, use a time series collection to improve performance and storage. For more information about the benefits of time series collections, see Time Series Collections.
About this Task
This page covers migrating data that is already in a MongoDB collection. If your data is in a relational database, use Relational Migrator to migrate your data into a time series collection.
You can use the $out aggregation stage to migrate data from an existing collection into a time series collection. MongoDB does not guarantee output order when you migrate data with $out. To maintain order, sort your data before you migrate it with an aggregation pipeline.
For more information about additional considerations for migrating your data, see Best Practices for Time Series Collections.
Note
To migrate your time series data with mongodump and mongorestore instead, run mongorestore with the --noIndexRestore option, because mongorestore can't create indexes on time series collections. To preserve the time ordering of your measurements, also run the command with the --maintainInsertionOrder option so that documents are inserted in order, from oldest to newest.
Next Steps
If your original collection had secondary indexes, manually recreate them now.
If your time series collection includes timeField values before 1970-01-01T00:00:00.000Z or after 2038-01-19T03:14:07.000Z, MongoDB logs a warning and disables some query optimizations that make use of the internal clustered index. To regain query performance and resolve the log warning, create a secondary index on the timeField.