0

I've a movielens database and, for example, to search all the documents who have "Titanic" in the title i run this Mango query:

{
   "selector": {
      "$or": [
         {
            "Title": {
               "$regex": "titanic"
            }
         },
         {
            "Title": {
               "$regex": "Titanic"
            }
         }
      ]
   }
}

And I have what I want. So my question now is: is possible to select a document only if I remember a substring?

For example, for the title "Tomb raider", I remember that contains "raider". I've tried with regex but it doesn't works.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

3

Use (?i) to make the regex case insensitive.

Place .* in front and at the end of the search term "titanic" for matching any character zero or more times.

{
  "selector": {
    "Title": {
      "$regex": "(?i).*titanic.*"
    }
  }
}
uminder
  • 23,831
  • 5
  • 37
  • 72
  • thank toy. Another question if you can: Do you know if it is possible to search on the basis of a substring? for example: title is "The Lion King" and i would search only "king" –  May 03 '20 at 09:45
  • 1
    @Malotino: That's what the selector in my answer does, searching by a substring. Simply use `"$regex": "(?i).*king.*"`. – uminder May 03 '20 at 09:48
  • I'm sorry, I got confused. I realized it only made CouchDB case insensitive. Thanks so much –  May 03 '20 at 09:54