question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regex: Error: Can't use $options with String

See original GitHub issue

As defined in the MongoDB documentation, the following syntax :

find(name: { $regex : 'abc', $options: 'i' } )

is correct.

However, I’ve got the error Can’t use $options with String

The same query works when I use directly the mongo shell. I’m using mongoose 2.3.10 and mongo 2.0

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Reactions:2
  • Comments:16

github_iconTop GitHub Comments

17reactions
mkopalacommented, Jan 6, 2012

I’m having an almost identical issue, except that I’m using a variable:

x = 'abc'
find({name: { $regex : x, $options: 'i' }} )

and getting the same error. I had to solve it with:

find({ name: new RegExp(x, 'i')}})
4reactions
aheckmanncommented, Nov 7, 2011

just pass a RegExp directly:

find(name: { /abc/i } )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose Error: Can't use $or with String - Stack Overflow
When using $or with "expressions" that are equality checks for the value of the same field, use the $in operator instead of the...
Read more >
Can't use $regex with String - Google Groups
); I run this against mongoose 2.1.0 (updated a few seconds ago via npm), and it fails with the following error message: Error:...
Read more >
Using $regex inside an $or: error
However I'm getting this error from mongoosejs: ERR: [Error: Can't use $options with Array.] While the same works in the mongodb command line...
Read more >
$regex — MongoDB Manual
Provides regular expression capabilities for pattern matching strings in queries. MongoDB uses Perl compatible regular expressions (i.e. "PCRE" ) version 8.42 ...
Read more >
perlre - Perl regular expressions - Perldoc Browser
A single /x tells the regular expression parser to ignore most whitespace that is neither backslashed nor within a bracketed character class. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found