mongo find query on joda datetime

微笑、不失礼 提交于 2019-12-13 01:27:05

问题


i am trying to use find query in mongodb to determine the records on that specific date , the query is working fine when i pass it the normal date object and if i find according to dateCreated field, but for joda date field, i don't know how should i form a joda date

right now i am using this query for normal records

var from =  new Date('2015-05-18T00:00:00.000Z'); 
var to =  new Date('2016-05-19T00:00:00.000Z'); 
db.delivery.find( {"dateCreated" : { $gte:from,$lt:to } } );

now i also have a field called deliveryDate which is of type joda date and stored like this

"deliveryDate" : {
    "jodaType" : "org.joda.time.DateTime",
    "interval_start" : ISODate("2015-03-28T18:30:00Z"),
    "interval_end" : ISODate("2015-03-28T18:30:00Z"),
    "jodaField_zone" : "UTC",
    "time" : NumberLong("1427567400000"),
    "jodaField_dayOfMonth" : 28,
    "jodaField_hourOfDay" : 18,
    "jodaField_minuteOfHour" : 30,
    "jodaField_millisOfSecond" : 0,
    "jodaField_monthOfYear" : 3,
    "jodaField_year" : 2015
},

i googled a lot but with no success, i have no idea how can i query for joda date ,please help!


回答1:


Your joda date is serialised into a nested JSON object. You should be able to query on it using interterval_start

db.delivery.find( {"deliveryDate.interval_start" : { $gte:from,$lt:to } } );


来源:https://stackoverflow.com/questions/35403356/mongo-find-query-on-joda-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!