Mongodb - how can I query by date range?

mongodb, mongoid

Solution

I'm going to assume you are using mongoid by the way the field was declared.

You would want to use something like this:

Model.where(
  :confirmed_at.gte => Time.now,
  :confirmed_at.lte => 10.minutes.ago
)

Problem

I am new to Mongo. I am trying to query for a date range. The user model has this field: ``` field :confirmed_at, :type => Time ``` could someone help me write a query to get users who confirmed their account for some time range? Here is the error and the query I am trying: ``` > db.users.where(:confirmed_at.gte => Time.now, :confirmed_at.lte => 10.minutes.ago) Tue May 29 17:45:37 SyntaxError: syntax error (shell):1 Model.where(:confirmed_at.gte => Time.now, :confirmed_at.lte => 10.minutes.ago) Tue May 29 17:56:15 SyntaxError: syntax error (shell):1 ``` Thanks!

Original source