mongodb - Search Mongo Document based on BSON DateTime -
my mongo document looks below -
{ "_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"
}
i trying query below document using below query -
db.getcollection('transaction').find({ starttime: { "$gt" : { "$date" : (new isodate("2018-07-25t23:56:36.822z")*1) } } })
i result. when try use less , greater don't result. not sure best way query above document.
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) } } })
Comments
Post a Comment