0

I know how to find embedded documents that equal a certain value using the following syntax:

Location.where("address.country" => 'USA').first

But how do you query for when it does not equal the value? Thanks!

2 Answers 2

1

For one, you can use standard mongodb $ne operator.

Location.where("address.country" => {'$ne' => 'USA'}).first

With mongoid you can use a little sugar

Location.where(:"address.country".ne => 'USA').first
#              ^ note the colon here. It converts string to symbol. 
0

You can use this also,

Location.where("address.country".to_sym.ne => ['Australia', 'India'])

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.