The scenario.
A large set of devices connected to a back-end (1.000.000).
Each few time the devices reports values, each value has got its time associated.
I want to store all the values to read them in the future to make graphics.
We need to locate each value to each second in the time.
Propossed data structure in mongo:
Option 1: (data as array of objects)
{
device_id: [string],
data: [
{ts: [date], val1: [any], ..., valn:[any]},
{ts: [date], val1: [any], ..., valn:[any]},
]
}
Option 2 (data with date as property to object)
{
device_id: [string],
data: [
"2022-01-01T00:00:01": { val1: [any], ..., valn:[any] },
...
"2022-01-01T00:00:02": { val1: [any], ..., valn:[any] },
]
}
Option 3 (data with date as property to array)
{
device_id: [string],
data: [
"2022-01-01T00:00:01": [[any], ..., [any]],
...
"2022-01-01T00:00:02": [[any], ..., [any]],
]
}
Option 4: (data with values and each document is a device_id with a time (the second))
{
device_id: [string],
ts:[date], // <-- each second
data: {
val1: [any], ..., valn:[any]
}
}
Option 5: (data with values in array and each document is a device_id with a time (the second))
{
device_id: [string],
ts:[date], // <-- each second
data: [[any], ..., valn:[any]] // each value has got a position
}
Any other recomendation??
CodePudding user response:
Do not want to make your choice even more difficult , but I would bet on following options:
Option 1:
collection_name-> device_id , doc--> { _id:ObjectId , ts:[date] , val1:any ,... , valn:any }
Option 2:
database_name-> device_id , collection_name-> [date] , doc-> { _id:ObjectId , ts:[date] , val1:any ,... , valn:any }
Option 3: ( Sharded database/collection on compaund index/shard key--> device_id:1,ts:1 )
doc--> { _id:[device_id], ts:[date] , val1:any ,... , valn:any }
Also you may take a look on the special time series collections