Hi @ACHACHE_FRANCOIS and welcome to the MongoDB community!!
Could you please help me with the sample document for the above schema mentioned which would help me to reproduce the problem on the local environment.
In the meantime, I created my own sample documents to check for $elemMatch functionality in a time series collection:
Sample Document
[
{
timestamp: ISODate("2021-05-18T00:00:00.000Z"),
metadata: { sensorId: 5578, type: 'temperature' },
_id: ObjectId("632aa2743a5ebcfafa682a85"),
results: [ 1, 2, 3 ],
temp: 12
},
{
timestamp: ISODate("2021-05-18T00:00:00.000Z"),
metadata: { sensorId: 5578, type: 'temperature' },
_id: ObjectId("632aa27e3a5ebcfafa682a86"),
results: [ 82, 85, 88 ],
temp: 12
},
{
timestamp: ISODate("2022-09-20T10:54:17.944Z"),
results: [ 82, 85, 88 ],
_id: ObjectId("63299bd941f051910f8be559")
},
{
timestamp: ISODate("2022-09-20T10:54:26.328Z"),
results: [ 1, 2, 3 ],
_id: ObjectId("63299be241f051910f8be55a")
}
]
Query using $elemMatch
db.test.find( { results: { $elemMatch: { $gte: 80, $lt: 85 } } })
[
{
timestamp: ISODate("2021-05-18T00:00:00.000Z"),
metadata: { sensorId: 5578, type: 'temperature' },
_id: ObjectId("632aa27e3a5ebcfafa682a86"),
results: [ 82, 85, 88 ],
temp: 12
},
{
timestamp: ISODate("2022-09-20T10:54:17.944Z"),
results: [ 82, 85, 88 ],
_id: ObjectId("63299bd941f051910f8be559")
}
]
and it works as expected in the MongoDB version 6.0.
Best Regards
Aasawari