skip to Main Content

I’m currently running a query on MongoDB, the field I’m querying contains values such as 123245123 - Johnson-Perez. If I build a query such as {"name":/123245123/ix} I get tons of rows and that’s fine, however, as soon as you add the hypens {"name":/123245123 - Johnson-Perez/ix} I get 0 rows. Do you guys know what could be causing this? I’ve tried replacing the hyphens with [-] and putting the entire string in double quotes but it didn’t work. I have zero knowledge on regex so I don’t know what could be causing this.

2

Answers


  1. Chosen as BEST ANSWER

    Solved it, I have to escape the whitespaces as well as the hyphen and the dots.


  2. Try:

    {"name":/^[0-9]* - [A-Zaz]*$/ix}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search