0

我知道如何使用以下语法查找等于某个值的嵌入文档:

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

但是当它不等于该值时,您如何查询呢?谢谢!

4

2 回答 2

1

一方面,您可以使用标准的 mongodb $ne 运算符

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

用mongoid你可以用一点糖

Location.where(:"address.country".ne => 'USA').first
#              ^ note the colon here. It converts string to symbol. 
于 2012-10-29T07:04:43.660 回答
0

你也可以用这个,

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

于 2013-03-01T13:30:07.163 回答