Mongoid ModelName.collection.aggregate method with $match by dates.
Example:
Stat.collection.aggregate({
'$match' => {
'$and' => [
{ 'day' => { '$gte' => from.to_date.mongoize } },
{ 'day' => { '$lte' => to.to_date.mongoize } }
]
},
})
When are you using aggregate function it will use the method from the moped library. This library doesn't know anything about your params and you need to be sure that you are passing the right params.
Lets you have 'field :day, type: Date' you should use mongoize mongoid extension to convert date to the right view of the date.
Written by Alexandr Korsak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#