RegExp from Query History is stored with invalid options

Using Compass 1.31.2 and if you use a filter like {email: RegExp('kory', 'i')}, it gets saved in the query history with the i option with no single quotes around it. When you select this item from the query history it gets added to the filter field like {email: RegExp('kory', i)} which is invalid and you need to add single quotes back to run the query.

Please fix this issue, as this is a constant annoyance when using query history.

Hello @Kory_Gill, Welcome to the forum!

It looks like, in Compass, you can form the regex queries using any of the following four syntaxes (see below). I see that the query entered is sometimes saved in the history with a different syntax.

When you select the query from the history and run it, the query runs fine (for all the syntaxes). But, when you type the same syntax from the history it doesn’t work - this is so for the query formats (3) and (4). The formats (1) and (2) work fine.

(1)

{ 'author': { '$regex': 'well', '$options': 'i' } } // Entered query
{ author: { $regex: 'well', $options: 'i' } }       // Stored in history

(2)

{ 'author': { '$regex': /well/, '$options': 'i' } }
{ author: { $regex: RegExp('well'), $options: 'i' } }

(3)

{ 'author': { '$regex': /well/i } }
{ author: { $regex: RegExp('well', i) } }

(4)

{ 'author': /well/i  }
{ author: RegExp('well', i) }

Reference: $regex

1 Like