批量查询:
db.OriginalMonitoringData.find({SensorCommonId:"874341de-cc58-44a9-8cd1-e90e8ba5a0d6"})
条件查询: (>) 大于 - $gt (<) 小于 - $lt (>=) 大于等于 - $gte (<= ) 小于等于 - $lte
#查询大于1小于1.1之间的数据
db.OriginalMonitoringData.find({Data1:{"$gte":1,"$lte":1.1}})
db.OriginalMonitoringData.find({"$and":[{Data1:{"$gte":1}},{Data1:{"$lte":1.1}}]})
查询一段时间内的数据
db.getCollection("OriginalMonitoringData").find({"Time":{"$gte":ISODate("2021-10-18T17:15:33.303Z"),"$lte":ISODate("2021-10-18T17:16:33.303Z")}})
联合查询一段时间内某测点的数据
#and联合查询
db.getCollection("OriginalMonitoringData").find({"$and":[{"Time":{"$gte":ISODate("2021-10-18T17:15:33.303Z"),"$lte":ISODate("2021-10-18T17:16:33.303Z")}},{SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}]})
或“or”查询小于"2021-10-18T17:15:33.303Z",大于"2021-10-18T17:16:33.303Z"这两段时间
db.getCollection("OriginalMonitoringData").find({$or:[{"Time":{"$lte":ISODate("2021-10-18T17:15:33.303Z"),"$gte":ISODate("2021-10-18T17:16:33.303Z")}}]})
模糊查询()
#含有5的SensorCommonId
db.OriginalMonitoringData.find({SensorCommonId:/5/})
#以5开头的SensorCommonId
db.OriginalMonitoringData.find({SensorCommonId:/^5/})
#以5结尾的SensorCommonId
db.OriginalMonitoringData.find({SensorCommonId:/5$/})
查询后展示制定列
#查询SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67",但是只展示_id
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"},{_id:true})
升序降序
#按照Time降序
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).sort({Time:-1})
#按照Time升序
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).sort({Time:1})
查询制定位置的数据
#查询前10条数据
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).limit(10)
#查询后10条数据
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).skip(10)
#查询5-10之间的数据
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).limit(10),skip(5)
统计查询到的数据数量
db.OriginalMonitoringData.find({SensorCommonId:"50bf7df2-7f41-4bc0-bca9-559891c7ac67"}).count()
|