0

次の構文を使用して、特定の値に等しい埋め込みドキュメントを見つける方法を知っています。

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

しかし、それが値と等しくない場合、どのように照会しますか? ありがとう!

4

2 に答える 2

1

1 つには、標準の mongodb $ne operatorを使用できます。

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 に答える