I was reading about the time-series collection. I am confused about a few terms, can someone please help me to understand?
Let’s say I want to fetch sensor data at every second of a day at various temperatures. That means data will always be different from what I recorded today than yesterday. I used to create separate collections for the day of the data and for each sensor. And my first document will always have some metadata field, like sensor name, a city in which the temp has checked etc. And these fields should not be repeated in sensor data documents.
So time series will work in this scenario? Will it create a single collection always for different types of sensor data OR every time a new collection will be created? how to keep common metadata for each sensor without repeating its value in data fields?
Since mongo allow the size of a document up to 16MB, then does it takes care of splitting data?
A time-series collection in MongoDB is a special type of collection that is optimized for storing time-series data. Time-series data is typically data that is captured over time and has a timestamp associated with each data point. Examples include sensor data, log data, and financial market data.
Looking at the use case you shared, I think the time-series collection would be a good fit for storing sensor data at different temperatures, with a timestamp associated with each data point. You can create a single TS collection to hold all the sensor data with metadata fields, such as sensor name and city, as document fields.
It is not necessary to do so as you can store all the data in a single collection. Internally, the data is stored in a bucket format based on its metadata and timestamp. By default, each bucket can store up to 1000 documents. As you add data from different sensors, internally the bucket will be created for each sensor based on its metadata and timestamp.
It is common practice to include metadata fields, such as sensor name and city, as fields within each document when storing data. I hope this addresses your query, but please let me know if you require any additional clarification.
The maximum BSON document size is 16 megabytes and it’s still applicable. Can you please clarify what you meant by splitting data here?
For more information, you can refer to the below resources