title: mongodb java $in query with $regex
body: <p>I am trying to write <code>$in</code> query with <code>$regex</code> in mongo+java. It's not working in mongo shell either. What I mean is I don't get any results but no query parse error either.
  Here's the final query I got from Java Debugger at the line where I say <code>collection.find(finalQuery)</code></p>
  <pre><code>{&quot;$and&quot;: [ 
      {&quot;$or&quot;: [
          {&quot;country&quot;: &quot;united states&quot;}
      ]}, 
      {&quot;businesses&quot;: {
          &quot;$in&quot;: [
              {&quot;$regex&quot;: &quot;^.*cardinal.*health.*$&quot;},
              {&quot;$regex&quot;: &quot;^.*the.*hartford.*$&quot;}
          ]
      }}
  ]}
  </code></pre>
  <p>Java Code snipet for Above query:</p>
  <pre class="lang-java prettyprint-override"><code>Set&lt;Pattern&gt; businesses = new HashSet&lt;Pattern&gt;();
              
  for(String st: srchTerms) {
  
      businesses.add(Pattern.compile(&quot;^&quot;+st.trim()+&quot;$&quot;));
  
  }
  srchTermQuery.append(&quot;businesses&quot;, new BasicDBObject(&quot;$in&quot;, businesses));
  </code></pre>
  <p>However, following query works in mongo shell but I don't know how to write it into java:</p>
  <pre><code>{&quot;registering_organization&quot;: {
      &quot;$in&quot;: [
          /^.*cardinal.*health.*$/,
          /^.*the.*hartford.*$/
      ]
  }}
  </code></pre>
  <p>Java Code add double quotes around regex if we try to define it as a string.</p>