couchdbcouchdb-mango

How to select a document if a field contains a substring


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.


Solution

  • 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.*"
        }
      }
    }