|
A quick test on my benchmark database showed that we're storing control.max.timestamp with millisecond precision, not rounding to the second:
MongoDB Enterprise > db.system.buckets.telemetry.aggregate([{$sort:{"control.max.timestamp":1}}, {$limit: 1}, {$project: {"control":1}}]).pretty()
|
{
|
"_id" : ObjectId("000000005db99da6e1198483"),
|
"control" : {
|
"version" : 2,
|
"min" : {
|
"_id" : ObjectId("620d8a0ea02f9f771425509d"),
|
"timestamp" : ISODate("1970-01-01T00:00:00Z"),
|
"temp" : 0
|
},
|
"max" : {
|
"_id" : ObjectId("620d8a4aa02f9f771426b82e"),
|
"timestamp" : ISODate("1970-01-01T00:00:09.208Z"),
|
"temp" : 98.1
|
},
|
"count" : 1000
|
}
|
}
|
So, the
{$sort: {"meta.sensorId": 1, "control.max.timestamp": -1}},
|
{$group: { _id: "$meta.sensorId",
|
bucket: {$first: "$_id"}, }}
|
DISTINCT_SCAN optimization should return the a bucket with a last point within ISODate's millisecond accuracy.
|