我的mongo文档如下所示 -
{
"_id" : ObjectId("5977dab66ea64e345288ceec"),
"transactionid" : "1",
"servicename" : "Reservation Service",
"starttime" : {
"dateTime" : true,
"symbol" : false,
"javaScriptWithScope" : false,
"string" : false,
"regularExpression" : false,
"javaScript" : false,
"double" : false,
"document" : false,
"DBPointer" : false,
"number" : false,
"boolean" : false,
"null" : false,
"bsonType" : "DATE_TIME",
"array" : false,
"int32" : false,
"int64" : false,
"binary" : false,
"value" : NumberLong(1501026996822),
"decimal128" : false,
"objectId" : false,
"timestamp" : false
},
"endtime" : {
"dateTime" : true,
"symbol" : false,
"javaScriptWithScope" : false,
"string" : false,
"regularExpression" : false,
"javaScript" : false,
"double" : false,
"document" : false,
"DBPointer" : false,
"number" : false,
"boolean" : false,
"null" : false,
"bsonType" : "DATE_TIME",
"array" : false,
"int32" : false,
"int64" : false,
"binary" : false,
"value" : NumberLong(1501026997875),
"decimal128" : false,
"objectId" : false,
"timestamp" : false
},
"status" : "Success",
"updatedby" : "muf",
"requestpayload" : "{\n \"service_header\": {\n \t\n \n \t\"service_name\": \"Reservation Service\",\n \t\"source_id\": \"Amex\",\n \t \t\"document_id\":\"1\",\n \t\"transaction_id\":\"1\"\n },\n \t\n \t\"airline\":\"united\",\n\t\"destination\":\"LAX\"\n\n\n}",
"responsepayload" : "[{\"departureDate\":\"2015/02/11\",\"airlineName\":\"United\",\"destination\":\"LAX\",\"price\":345.99,\"planeType\":\"Boeing 737\",\"code\":\"ER45if\",\"origin\":\"MUA\",\"emptySeats\":52},{\"departureDate\":\"2015/04/11\",\"airlineName\":\"United\",\"destination\":\"LAX\",\"price\":346.0,\"planeType\":\"Boeing 777\",\"code\":\"ER45jd\",\"origin\":\"MUA\",\"emptySeats\":12},{\"departureDate\":\"2015/06/11\",\"airlineName\":\"United\",\"destination\":\"LAX\",\"price\":423.0,\"planeType\":\"Boeing 707\",\"code\":\"ER0945\",\"origin\":\"MUA\",\"emptySeats\":0}]",
"exception" : "",
"requesthost" : "localhost",
"requestport" : "8086",
"requestpath" : "/flights"
}
我正在尝试使用以下查询查询以下文档 -
db.getCollection('Transaction').find({ starttime: { "$gt" : { "$date" : (new ISODate("2018-07-25T23:56:36.822Z")*1) } } })
我确实得到了结果。然而,当我尝试使用少于和大于一起时,我没有得到任何结果。我不确定查询上述文档的最佳方法是什么。
db.getCollection('Transaction').find({ starttime: { "$gt" : { "$date" : (new ISODate("2015-07-25T23:56:36.822Z")*1) } , "$lt" : { "$date" : (new ISODate("2018-07-25T23:56:36.822Z")*1) } } })