0

I have this:

let query = {
  title: {
    $regex: ".*" + req.params.term + ".*"
  }
}

Which helps me to find "Tel Aviv" in the collection using the "v" or "viv" or "T" or "A" in the term.

However when I am trying to search for "t" or "a" which are inside the string but are need to be capital - it returns nothing.

How to set a good regex which results with "LIKE" function as I have now but also with aware of capital letters?

Thanks.

Raz Buchnik
  • 7,753
  • 14
  • 53
  • 96
  • 1
    Possible duplicate of [How to query MongoDB with "like"?](https://stackoverflow.com/questions/3305561/how-to-query-mongodb-with-like) – Ashh Sep 20 '18 at 06:24
  • @AnthonyWinzlet This question is without capital letters. My does. – Raz Buchnik Sep 20 '18 at 07:39
  • If you will see the answers posted in the duplicate then you might get the idea – Ashh Sep 20 '18 at 07:44

1 Answers1

2

You may have to specify options flag for case insensitivity and your modified query should look like this,

let query = {
  title: {
    $regex: ".*" + req.params.term + ".*",$options:"$i"
  }
}
Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36