我正在尝试在给定的时间范围内检索数据。 使用以下查询
db.readings.find({TS:{"$gte":"16/12/18 00:00:00","$lte":"17/12/18 24:00:00"}});
,由于某种原因,它没有返回我想要的数据。
{ "_id" : ObjectId("5b4d31843fa3b6103e63d293"), "IMEI" : NumberLong("353438065610052"), "TS" : "17/07/18 00:00:00", "P" : "MK6E_NORECO2-DTB-Delta", "A" : 1, "ST" : 0, "V1" : 31290, "V2" : 19678, "V3" : 62568, "V4" : 19289, "V5" : 42839, "V6" : 19694, "V7" : 12496, "V8" : 17825, "status" : "DONE" }
{ "_id" : ObjectId("5b4d318f3fa3b666736c767d"), "IMEI" : NumberLong("353438065610052"), "TS" : "17/07/18 00:00:00", "P" : "MK6E_NORECO2-DTB-Delta", "A" : 1, "ST" : 8, "V1" : 13357, "V2" : 17537, "V3" : 44380, "V4" : 17860, "V5" : 43819, "V6" : 17266, "V7" : 42630, "V8" : 17266, "V9" : 0, "V10" : 0, "V11" : 45080, "V12" : 16819, "V13" : 44458, "V14" : 16819, "V15" : 0, "V16" : 0, "V17" : 53075, "V18" : 48977, "V19" : 31968, "V20" : 17007, "status" : "DONE" }
{ "_id" : ObjectId("5b4d31953fa3b667ee516878"), "IMEI" : NumberLong("353438063633361"), "TS" : "17/07/18 00:00:00", "P" : "Integra_RFM Main Power Supply", "A" : 1, "ST" : 0, "V1" : 16880, "V2" : 0, "V3" : 16880, "V4" : 0, "V5" : 16256, "V6" : 0, "V7" : 18323, "V8" : 41728, "V9" : 17224, "V10" : 0, "V11" : 16904, "V12" : 0, "V13" : 16672, "V14" : 0, "V15" : 0, "V16" : 0, "V17" : 0, "V18" : 0, "V19" : 16576, "V20" : 0, "status" : "DONE" }
但是如果我使用此值调整查询
db.readings.find({TS:{"$gte":"16/12/18 00:00:00","$lte":"16/12/18 24:00:00"}});
它给了我想要的结果。
{ "_id" : ObjectId("5c17023d3fa3b60d8f136b47"), "IMEI" : NumberLong("353438063612373"), "TS" : "16/12/18 01:03:00", "P" : "MK6N", "A" : 10, "ST" : 1536, "V1" : 18492, "V2" : 8157, "status" : "INITIAL_INSERT" }
{ "_id" : ObjectId("5c17023d3fa3b60d8f136b47"), "IMEI" : NumberLong("353438063612373"), "TS" : "16/12/18 01:03:00", "P" : "MK6N", "A" : 10, "ST" : 1536, "V1" : 18492, "V2" : 8157, "status" : "INITIAL_INSERT" }
{ "_id" : ObjectId("5c1702b33fa3b60d99474007"), "IMEI" : NumberLong("353438063612373"), "TS" : "16/12/18 01:03:00", "P" : "MK6N", "A" : 10, "ST" : 1536, "V1" : 18492, "V2" : 8157, "status" : "INITIAL_INSERT" }
检查表后,我发现“ TS”实际上是一个字符串。
答案 0 :(得分:2)
可能是24:00:00
可能导致此问题吗? IMO,它应该是00:00:00
或24:00:00
,而不是两者。
您的17/12/18 24:00:00
将是18/12/18 00:00:00
或17/12/18 23:59:59
或
您可以尝试db.readings.find({TS:{"$gte":new Date("16/12/18 00:00:00"),"$lte":new Date("17/12/18 23:59:59")}});