次の構文を使用して、特定の値に等しい埋め込みドキュメントを見つける方法を知っています。
Location.where("address.country" => 'USA').first
しかし、それが値と等しくない場合、どのように照会しますか? ありがとう!
次の構文を使用して、特定の値に等しい埋め込みドキュメントを見つける方法を知っています。
Location.where("address.country" => 'USA').first
しかし、それが値と等しくない場合、どのように照会しますか? ありがとう!
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.
これも使えますが、
Location.where("address.country".to_sym.ne => ['Australia', 'India'])