swa
swa

Reputation: 21

Achieve case insensitivity for cloudant queries

My query has the following selector,

{
  "selector": {
    "_id": {
      "$gt": null
    },
    "series": {
      "$regex": "(?i)mario"
    }
  }
}

Now, if I have a document with series = mario12, the above query is returning this document which shouldn't happen. I want my query to only ignore the case of "mario".

How can I achieve case insensitivity?

Upvotes: 2

Views: 751

Answers (1)

markwatsonatx
markwatsonatx

Reputation: 3491

I'm not sure I understand the question exactly. If you only want to match the full word "mario" in a case-insensitive manner then you would use a selector like this:

{
  "selector": {
    "_id": {
      "$gt": null
    },
    "series": {
      "$regex": "^(?i)mario$"
    }
  }
}

This will match "mario", "Mario", "MARIO", etc, but will not match "mario12", "Mario12", "12Mario", etc.

Upvotes: 6

Related Questions