[COMPASS-2993] RegEx expressions not working in Compass 1.14.6 Created: 13/Jul/18  Updated: 27/Oct/23  Resolved: 14/Nov/18

Status: Closed
Project: Compass
Component/s: Compass
Affects Version/s: 1.14.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Manish Singh Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File compass_bug.PNG    

 Description   

Hello Team,

 

If you write a regex in Compass, it gives an error. The same works fine in the shell.

 

 

Regards,

Manish Singh



 Comments   
Comment by Vegar Vikan [ 26/Feb/20 ]

OK - I got something to work...

When searching for a digit, `[0..9]` works while `\d` does not..

Comment by Vegar Vikan [ 26/Feb/20 ]

How can this be 'Works as designed'?
Compass was designed to not support mongodb query syntax?

I can't get any regex syntax to work at all in aggregation pipelines.

Comment by Blake Jarsky [ 10/Feb/20 ]

I get the same error

Comment by Massimiliano Marcon [ 14/Nov/18 ]

MongoDB supports 3 syntaxes for regular expression matching:

 

 
{ <field>: { $regex: /pattern/, $options: '<options>' } }
{ <field>: { $regex: 'pattern', $options: '<options>' } }
{ <field>: { $regex: /pattern/<options> } }

 

In Compass we currently only support the second one. Your query could be therefore re-written as:

 

{"awards.text": {$regex:'^Won.*'}}

To be safe, you can always use JavaScript's RegExp('regex', 'options').

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