MongoDBは質問すると同じではありません

MongoDBは質問すると同じではありません

MongoDB でテキスト フィールドが '' (空白) ではないクエリを表示しようとしています

{ 'name' : { $not : '' }}

しかし、エラーが発生しますinvalid use of $not

ドキュメントを確認しましたが、使用されている例は複雑なケース(正規表現と$not別の演算子の否定を使用)向けです。

私がやろうとしている単純なことをどうやってやればいいのでしょうか?

ベストアンサー1

$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" : "" }

おすすめ記事