-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.0.2, 2.5.3
-
Component/s: Querying
-
Environment:Windows server 2008 r2 sp1
Developped with mongo C++ server and Visual Studio 2010
-
Query
-
Windows
This page documents that $not with $regex is disallowed, but this behavior seems counterintuitive from an end-user perspective and perhaps could be reconsidered.
Setup a simple repro:
> t = db.t test.t > t.drop() false > t.save({y: "x"}) { "ok" : 1, "n" : 1 } > t.save({y: "z"}) { "ok" : 1, "n" : 1 }
Using $not with a raw BSON regex works as expected:
> c.find({y: {$not: /x/}}) { "_id" : ObjectId("52828c701b91a96125c119ce"), "y" : "z" }
But using $not with $regex returns an error:
> c.find({y: {$not: {$regex: "x"}}}) error: { "$err" : "bad query: BadValue $not cannot have a regex", "code" : 16810 }
Original description:
I tried to do a "Not like" query with following codes :
BSONObj test;
test = BSON(std::string("$regex")<<myStr<<std::string("$options")<<"i");
test = BSON(std::string("$not")<<test);
test = BSON("x"<<test);
It doesn't work, saying that $not operator and $regex operator do not work together.
However, I tried to build with object builder :
BSONObjBuilder x;
x.appendRegex( "$not" , myStr);
BSONObj test = BSON( "x" << x.obj() );
Meanwhile, the '.jsonString()' of these two objects are the same.
Thus I think it's a bug of the C++ driver.
- is related to
-
SERVER-13779 Allow $not to be applied to $regex (currently only /regex/ syntax is allowed)
- Closed