mongodb按照meterId分组查询em_meter_data表communityId=46并且meteringTime在2023-09-06 000000和2023-09-06 235959之间的数据找出value为空的数据写出语句
以下是使用MongoDB的查询语句,按照meterId分组,查询em_meter_data表中符合条件的数据:
db.em_meter_data.aggregate([
{
$match: {
communityId: 46,
meteringTime: {
$gte: ISODate("2023-09-06T00:00:00Z"),
$lte: ISODate("2023-09-06T23:59:59Z")
},
value: ""
}
},
{
$group: {
_id: "$meterId",
data: { $push: "$$ROOT" }
}
}
])
上述查询语句中使用了MongoDB的aggregate管道操作符。首先使用$match操作符筛选出符合条件的数据,其中communityId为46,meteringTime在指定时间范围内,且value为空。然后使用$group操作符按照meterId分组,将每个分组的数据存储在data字段中。最后返回每个分组的结果
原文地址: http://www.cveoy.top/t/topic/i1z4 著作权归作者所有。请勿转载和采集!