[mongoid] What would be the best way to query Date?

144 views
Skip to first unread message

Joshua Partogi

unread,
May 17, 2010, 9:06:42 AM5/17/10
to mon...@googlegroups.com
Dear all,

I am trying to query a date field and find a data which has a due_date
equals to today.

This is what I did:
Bar.where(:due_date => { "$lt" => Date.end_of_day, "$gt" =>
Date.beginning_of_day } )


But it fetch all the record instead. Would anyone be able to recommend
an approach that works?

Thank you very much in advance for your help.


Kind regards,
Joshua

--
http://twitter.com/scrum8

Durran Jordan

unread,
May 17, 2010, 11:44:38 AM5/17/10
to mon...@googlegroups.com
Convert your dates to times. Unless of course your dates are pre-epoch
then you're screwed right now:

http://jira.mongodb.org/browse/SERVER-405

Have a few ideas on how to have Mongoid fix this for you instead...
I'll alert when they go in.
Reply all
Reply to author
Forward
0 new messages