-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I'm not sure if this issue is with Mongoid or MongoDB, but these are the results when querying with $lte. The return value should be nil.
scope :on_date, lambda
{ |date| where(:_id.gte => date.beginning_of_day.utc, :_id.lte => date.end_of_day.utc) }1.9.3-p125 :011 > h = MarketHour.on_date(Time.zone.now).first
MONGODB wall_street_game_production['market_hours'].find({:_id=>{"$gte"=>2012-04-05 04:00:00 UTC, "$lte"=>2012-04-06 03:59:59 UTC}}).limit(-1).sort([[:_id, :asc]])
=> # MarketHour _id: 2012-04-06 04:00:00 UTC, _type: nil, is_open: false, open_time: 2012-04-06 04:00:00 UTC, close_time: 2012-04-06 04:00:00 UTC
1.9.3-p125 :005 > date = Time.zone.now
1.9.3-p125 :006 > h = MarketHour.where(:_id.gte => date.beginning_of_day.utc).where(:_id.lte => date.end_of_day.utc).first
MONGODB wall_street_game_production['market_hours'].find({"$and"=>[{:_id=>{"$gte"=>2012-04-05 04:00:00 UTC}}, {:_id=>{"$lte"=>2012-04-06 03:59:59 UTC}}]}).limit(-1).sort([[:_id, :asc]])
=> # MarketHour _id: 2012-04-06 04:00:00 UTC, _type: nil, is_open: false, open_time: 2012-04-06 04:00:00 UTC, close_time: 2012-04-06 04:00:00 UTC
I was able to fix this by changing $lte to $lt, however the same query should work with $lte unless I'm mistaken.