title: Gettting the index of an element in an array of objects according to a field using regex in MongoDB
body: <p>Lets say I have the following partial document</p>
  
  <pre><code>{ 
    "groups": [
    {
      "text": "Example text 1 blah blah blah",
      "key": 1,
    },
    {
      "text": "Example text 2 blah blah blah",
      "key": 2,
    },
    {
      "text": "Example text 3 blah blah blah",
      "key": 3,
    },
  }
  </code></pre>
  
  <p>I would like to search for 'Example text 2' using regex in the text field and retrieve the index of the object.
  Basically combination of $indexOfArray and regex, I couldn't find a way to use them together.</p>
  
  <p>What I'm trying to do is to first check if an object with the matching field exists, if it does, change the key value and bump this object to index 0 (first in the array), is there a better way to do this? (I'm planning on swapping the found object index with index 0)</p>