dtvvha
Last Updated: February 25, 2016
·
2.688K
· oivoodoo

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.

1 Response
Add your response

11316

Thunk you.

over 1 year ago ·