title: Java/Groovy monogodb nested query with both AND and OR
body: <p>I am having hard time converting the below nested mongodb query with <code>$and</code> and <code>$or</code> to java/groovy</p>
  
  <pre><code>db.personSync.find({
             $and:[
                  {$or:[
                       { "name" : { "$regex" : "(?i)^test1" , "$options" : "i"}},
                       { "name" : { "$regex" : "(?i)^dev" , "$options" : "i"}}                                             
                  ]},
                  { "email" : { "$regex" : "(?i)^test" , "$options" : "i"}}
              ]}
  );  
              ]}
  );          
  </code></pre>
  
  <p>I was able to write code for $or part as below</p>
  
  <pre><code>def mongoCritera = new ArrayList&lt;BasicDBObject&gt;(); 
  mongoCritera.add('name', java.util.regex.Pattern.compile('(?i)^test1`'))
  mongoCritera.add('name', java.util.regex.Pattern.compile('(?i)^dev`'))
  def query = new BasicDBObject("\$or", mongoCritera);
  collection.find(query);
  </code></pre>
  
  <p>But I couldn't accommodate $and logic, can someone please help me with this?</p>