[COMPASS-3120] No support for negative regex, { $not: /regex/ } not accepted in query bar Created: 09/Sep/18  Updated: 29/Oct/23  Resolved: 24/Mar/20

Status: Closed
Project: Compass
Component/s: Compass, Grammar, Query Bar
Affects Version/s: 1.15.1
Fix Version/s: 1.22.0

Type: Bug Priority: Major - P3
Reporter: Brian Blevins Assignee: Durran Jordan
Resolution: Fixed Votes: 3
Labels: query-parser
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2018-09-09-09-31-50-970.png     PNG File image-2018-09-09-09-32-25-075.png    
Issue Links:
Problem/Incident
causes COMPASS-4146 Disable validation in agg builder, qu... Closed
Related
related to COMPASS-3527 Add support for $not with $regex Closed
Epic Link: COMPASS-3417
Sprint: Iteration Zebra

 Description   

 

In the mongo shell, the $not operator is allowed and documented for use against regular expressions.

$not

db.inventory.find( { item: { $not: /^p.*/ } } )

However, the Compass query bar does not accept this query.

Please refer to the screenshots with both standard regex expression and $regex.

 

 

 



 Comments   
Comment by Brian Blevins [ 18/Jan/19 ]

 
With the understanding that regular expression evaluation on the database server is a relatively expensive operation and complex expressions such as the following are even more taxing on server resources, it is possible in some situations to push the negation down into the regular expression itself.  This provides a workaround for the lack of support for $not in the Compass query bar for some use cases.

To find all documents where the start station name does not contain "Ave", you can use the following:

{ 'start station name': { $regex: '^((?!Ave).)*$' }}

The example from the description of this ticket above can be expressed in Compass as:

{ 'item': { $regex: '^((?!^p).)*$' }}

Please refer to the documentation on $regex and PCRE vs Javascript for more information on the regular expressions accepted by $regex.  Since reasoning about negative lookahead in regular expressions can be challenging, very thorough testing of this mechanism recommended.

 

Comment by Randy Raymond [X] [ 07/Nov/18 ]

I am glad this is here. I have been trying to run my query and wondered why it was not working.

Comment by Anna Herlihy (Inactive) [ 12/Sep/18 ]

This will go away when language-modes is implemented, but that likely won't be for another quarter or two so we can document this in the meantime. 

Generated at Wed Feb 07 22:32:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.