0

I am using MongoId 3,Rails 3.2 ,Ruby 1.9.3.

I wanted to query only part of a date, such as the day, week or month.

So for example, let's say we need to find all users that signed up on a Wednesday OR get all users whose birthday is on 25 day Or get all users who born in April month(not specific to particular year here) etc..

In Mysql we have select * from users where extract(dow from created_at) = 3;

But how can we perform this using MongoId.

2 Answers 2

0

Here is a pretty handy cookbook on querying data ranges on Mongodb: http://cookbook.mongodb.org/patterns/date_range/ . and you can just create the query almost in the same way on Mongoid, using .where

1
  • The question wasn't about date ranges though. "All users born in April" won't work with a reasonable date range query and where has potentially some significant performance issues. Sep 17, 2013 at 19:11
0

I think the aggregation framework is a better fit for this. This question discusses the use of date operators in aggregation.

I've not had much experience with Mongoid, but it seems like it should support aggregation just fine, as long as you are using a recent version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.