|
This is indeed invalid use of $not because, as specified by the documentation, the argument to $not must be an "operator expression". Operator expressions, in this setting, are things like
{$gt: 4}, {$exists: true}, etc.
|
That is, an operator expression is a document whose only key is a "$"-prefixed query operator.
Validation for $not has been added, so now your example will give an error. Here's what I get running against development release 2.5.3:
> c = db.c
|
test.c
|
> c.drop()
|
true
|
> c.save({x: 1, y: 2})
|
> c.save({x: 3, y: 4})
|
> c.save({x: 5, y: 6})
|
> c.find()
|
{ "_id" : ObjectId("52827adca4682f073415c108"), "x" : 1, "y" : 2 }
|
{ "_id" : ObjectId("52827ae3a4682f073415c109"), "x" : 3, "y" : 4 }
|
{ "_id" : ObjectId("52827af2a4682f073415c10a"), "x" : 5, "y" : 6 }
|
> db.test.find({$not: {x:1, y:1}})
|
error: {
|
"$err" : "bad query: BadValue unknown top level operator: $not",
|
"code" : 16810
|
}
|
> db.test.find({x: {$not: 1}})
|
error: { "$err" : "invalid use of $not", "code" : 13041 }
|
Given that the error checking has been tightened, I'm going to close this issue as fixed.
|