[SERVER-4805] query { $not : { $regex : /x/ } } doesn't work Created: 28/Jan/12  Updated: 06/Dec/22  Resolved: 12/Jan/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.0.2, 2.5.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: aochen Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 1
Labels: bson, commands, query, query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows server 2008 r2 sp1
Developped with mongo C++ server and Visual Studio 2010


Attachments: File server4805.js    
Issue Links:
Related
is related to SERVER-13779 Allow $not to be applied to $regex (c... Closed
Assigned Teams:
Query
Operating System: Windows
Participants:

 Description   

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.



 Comments   
Comment by J Rassi [ 12/Jan/16 ]

Closing as a duplicate of SERVER-13779.

Generated at Thu Feb 08 03:07:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.