回答:
使用$ne
- $not
標準演算子が後に続きます:
$ne
等しくないことを表すの例:
use test
switched to db test
db.test.insert({author : 'me', post: ""})
db.test.insert({author : 'you', post: "how to query"})
db.test.find({'post': {$ne : ""}})
{ "_id" : ObjectId("4f68b1a7768972d396fe2268"), "author" : "you", "post" : "how to query" }
そして今$not
、述語($ne
)を取り、それを否定($not
)します:
db.test.find({'post': {$not: {$ne : ""}}})
{ "_id" : ObjectId("4f68b19c768972d396fe2267"), "author" : "me", "post" : "" }
$not :{ $ne
手段 $eq
、これはあなたが言うしようとしていた何ですか?
複数を実行したい場合$ne
は、
db.users.find({name : {$nin : ["mary", "dick", "jane"]}})
$ne
代わりに使用$not
http://docs.mongodb.org/manual/reference/operator/ne/#op._S_ne
db.collections.find({"name": {$ne: ""}});
Mongo docsから:
$not
オペレータは、他の事業者に影響を与え、独立してフィールドや文書を確認することができません。したがって、$not
論理和に演算子を使用し、演算子を使用して$ne
フィールドの内容を直接テストします。
フィールドを直接テストしているので、$ne
ここで使用する適切な演算子です。
編集:
使用したい状況$not
は次のとおりです。
db.inventory.find( { price: { $not: { $gt: 1.99 } } } )
これにより、次のすべてのドキュメントが選択されます。
null
配列にaがあり、それを避けたい場合:
db.test.find({"contain" : {$ne :[] }}).pretty()
$ne
ために「等しくない」を指します。