I’m exploring how to use the Time Series collection in a MongoDB replica set (on-premise community edition 6.0.6).
I have define a TS collection as below:
{
name:"ts1",
type:"timeseries",
options:{
timeseries:{
timeField:"timestamp",
metaField:"meta",
granularity: "seconds",
bucketMaxSpanSeconds: 3600
}
},
info: {readonly: false}
},
Below same example data from “db.system.buckets.ts1”:
{
_id: ObjectId("646b3ff0c5a28d25568373ae"),
control: {
version: 1,
min: {
timestamp: ISODate("2023-05-22T10:12:00.000Z"),
cowe: 201.939,
pmnp10: 14,
hum: 62.3,
pmnp50: 0,
pmspug10: 3,
pm10: 60.37,
calpm10: '',
no2ae: 397.264,
calco: '',
batt: 100,
temp: 24,
pmnp05: 166,
co: 0.583,
pmspug100: 4,
pmaeug10: 3,
no2: 50.284,
vafe: 262.362,
pmnp100: 0,
pmaeug25: 4,
no2o3ae: 409.052,
calpm2_5: '',
pmaeug100: 4,
no2we: 109.925,
pm25: 198.91,
no2o3we: 422.077,
calno2: '',
pmnp03: 537,
calo3: '',
pmnp25: 4,
pmspug25: 4,
coae: 160.378,
pmdiag: 0,
o3: 40.285,
_id: ObjectId("646efee320e52ccbfd5ef937")
},
max: {
timestamp: ISODate("2023-05-22T10:13:00.000Z"),
cowe: 300.939,
pmnp10: 14,
hum: 62.3,
pmnp50: 0,
pmspug10: 3,
pm10: 60.37,
calpm10: 'test',
no2ae: 397.264,
calco: '',
batt: 100,
temp: 24,
pmnp05: 166,
co: 0.583,
pmspug100: 4,
pmaeug10: 3,
no2: 50.284,
vafe: 262.362,
pmnp100: 0,
pmaeug25: 4,
no2o3ae: 409.052,
calpm2_5: 'test',
pmaeug100: 4,
no2we: 109.925,
pm25: 198.91,
no2o3we: 422.077,
calno2: '',
pmnp03: 537,
calo3: 'test',
pmnp25: 4,
pmspug25: 4,
coae: 160.378,
pmdiag: 0,
o3: 40.285,
_id: ObjectId("646eff3220e52ccbfd5ef939")
}
},
meta: {
idafe: 'AirH358',
lbllocation: 'Poli-TO-1',
location: {
coordinates: [15.047446452336533, 37.36084832653023],
type: 'Point'
},
schemaver: 1,
verfmw: 'AH_1.3.1'
},
data: {
vafe: {
'0': 262.362,
'1': 262.362
},
no2we: {
'0': 109.925,
'1': 109.925
},
cowe: {
'0': 201.939,
'1': 300.939
},
no2: {
'0': 50.284,
'1': 50.284
},
coae: {
'0': 160.378,
'1': 160.378
},
calco: {
'0': '',
'1': ''
},
temp: {
'0': 24,
'1': 24
},
pmnp10: {
'0': 14,
'1': 14
},
timestamp: {
'0': ISODate("2023-05-22T10:12:00.000Z"),
'1': ISODate("2023-05-22T10:13:00.000Z")
},
no2o3ae: {
'0': 409.052,
'1': 409.052
},
calno2: {
'0': '',
'1': ''
},
pmaeug100: {
'0': 4,
'1': 4
},
o3: {
'0': 40.285,
'1': 40.285
},
pmnp03: {
'0': 537,
'1': 537
},
hum: {
'0': 62.3,
'1': 62.3
},
pm25: {
'0': 198.91,
'1': 198.91
},
_id: {
'0': ObjectId("646efee320e52ccbfd5ef937"),
'1': ObjectId("646eff3220e52ccbfd5ef939")
},
pmdiag: {
'0': 0,
'1': 0
},
pmnp100: {
'0': 0,
'1': 0
},
no2ae: {
'0': 397.264,
'1': 397.264
},
pmaeug25: {
'0': 4,
'1': 4
},
pmspug25: {
'0': 4,
'1': 4
},
pmspug100: {
'0': 4,
'1': 4
},
pmaeug10: {
'0': 3,
'1': 3
},
batt: {
'0': 100,
'1': 100
},
pmnp50: {
'0': 0,
'1': 0
},
pm10: {
'0': 60.37,
'1': 60.37
},
calpm2_5: {
'0': '',
'1': 'test'
},
pmnp05: {
'0': 166,
'1': 166
},
pmnp25: {
'0': 4,
'1': 4
},
calpm10: {
'0': '',
'1': 'test'
},
no2o3we: {
'0': 422.077,
'1': 422.077
},
co: {
'0': 0.583,
'1': 0.583
},
pmspug10: {
'0': 3,
'1': 3
},
calo3: {
'0': '',
'1': 'test'
}
}
}
I would like to be able some sensor readings by timestamp or index, i.e. delete readings having index 1 or readings whose timestamp is greater than a set timestamp, but I’m not able to figure out how to design such a type of query given this specific schema.
Any suggestion/example?
Thanks!