title: Find match over Array of RegEx in MongoDB Collection
body: <p>Say I have a collection with these fields:</p>
  
  <pre><code>{
      "category" : "ONE",
      "data": [
          {
              "regex": "/^[0-9]{2}$/",
              "type" : "TYPE1"
          },
          {
              "regex": "/^[a-z]{3}$/",
              "type" : "TYPE2"
          }
          // etc
      ]
  }
  </code></pre>
  
  <p>So my input is "abc" so I'd like to obtain the corresponding type (or best match, although initially I'm assuming RegExes are exclusive). Is there any possible way to achieve this with decent performance? (that would be excluding iterating over each item of the RegEx array)</p>
  
  <p>Please note the schema could be re-arranged if possible, as this project is still in the design phase. So alternatives would be welcomed.</p>
  
  <p>Each category can have around 100 - 150 RegExes. I plan to have around 300 categories.
  But I do know that types are mutually exclusive. </p>
  
  <p>Real world example for one category: </p>
  
  <pre><code>type1=^34[0-9]{4}$, 
  type2=^54[0-9]{4}$, 
  type3=^39[0-9]{4}$, 
  type4=^1[5-9]{2}$, 
  type5=^2[4-9]{2,3}$
  </code></pre>