我正尝试在MongoDB中显示一个文本字段不是'‘(空白)的查询
{ 'name' : { $not : '' }}但是,我得到了错误invalid use of $not
我已经看过文档了,但他们使用的示例是针对复杂情况的(使用regexp和$not对另一个运算符求反)。
我该如何做我想做的这件简单的事情?
发布于 2012-03-21 00:37:02
使用$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" : "" }发布于 2013-07-11 21:32:49
如果您想执行多个$ne,那么可以这样做
db.users.find({name : {$nin : ["mary", "dick", "jane"]}})发布于 2012-03-21 00:37:30
使用$ne而不是$not
http://docs.mongodb.org/manual/reference/operator/ne/#op._S_ne
db.collections.find({"name": {$ne: ""}});https://stackoverflow.com/questions/9790878
复制相似问题