mongodb - How to find date between stat date and end date -


i have 2 fields in database start_date , end_date. how find if date passing in between these 2 dates.

model

class schedule   include mongoid::document    field :start_date, type: date   field :end_date, type: date  end 

simple activerecord query

schedule.where(["start_date <= ? , end_date >= ?", params[:date], params[:date] ]) 

date saved in database in following format

{ "_id" : objectid("559d182f6368611dbf000000"), "start_date" : isodate("2015-06-10t00:00:00.000z"), "end_date" : isodate("2015-07-10t00:00:00.000z") 

}

and parameter contain date "2015-06-10"

what query while using mongodb database mongoid?

this should work

 schedule.where(:start_date.lte => date, :end_date.gte => date) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -