Mongo Query For Regex In Specific Field Link to heading

Suppose you have a chat collection, the following will match any response beginning with “This is”.

{
  "id": "...",
  "response": "This is a good response"
}

I can query for:

{
  response: {
    $regex: "^This is"
  }
}

The $regex operator acts as a range operator, which should be considered in the [[mongodb-esr-rule|ESR rule]].