我每分钟都有一个数据流入Mongo集合,我使用下面的查询来获取指定时间范围之间的数据,
mongo_client.db("db")
.collection(collection)
.aggregate([
{
$addFields: {
timestampISO: {
$toLong: "$periodicMessageBase.messageTimestamp",
},
},
},
{
$match: {
deviceId: deviceId,
periodicMessageBase: {
$exists: true,
},
timestampISO: {
$lt: "1694008207000", // unix timestamp
$gte: "1695002207000",
},
},
},
{
$project: {
_id: 0,
DeviceID: "$deviceId",
Timestamp: "$timestampISO",
L1_VoltageAngleMean: {
$ifNull: [
{
$arrayElemAt: ["$periodicMessageBase.vAngle.meanVal", 0],
},
0,
],
}
},
},
])
.sort({
Timestamp: -1,
})
但是,当我搜索长时间范围而不是每分钟的数据时,是否有可能获得每小时的数据?