I’m having a difficult time doing something such as:
Something.where(:field => nil)
or
Something.where(:field => { '$eq' => nil })
What’s the right way to handle this in Mongoid?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s the right way to do it. To find cars whose engine is
nil, for example, use:If you’re trying to look for the absence of a field (rather than one that’s set to
nil), use the$existspredicate:Note that setting a field
footo beniland lacking a field namedfooare two different things.