title: Java MongoDB queries, inserting 2 '$or' conditions
body: <p>I am trying to generate a MongoDB query with Java like the following:</p>
  
  <pre><code>{
     "$or": [
        {
           "user": {
              "$exists": true
           }
        },
        {
           "parent": {
              "$exists":true
           }
        }
     ],
     "working": 1,
     "$or": [
        {
           "car.id": 3846,
           "car.mediaType": 1
        },
        {
           "car.matched.id": 3846,
           "car.matched.model": 1
        }
     ]
  }
  </code></pre>
  
  <p>But I cannot do it because when the second <code>$or</code> condition is being added, the first one is overwritten.</p>
  
  <p>I need to search with some of the results of each <code>$or</code>, I can't add it in the same <code>$or</code>. The code is:</p>
  
  <pre><code>import com.mongodb.BasicDBList;
  import com.mongodb.BasicDBObject;
  import com.mongodb.BasicDBObjectBuilder;
  
  public class Sample {
      public function mongoSearch()
      {
          BasicDBObjectBuilder queryBuidlerType = BasicDBObjectBuilder.start().add("working", 1);
  
          BasicDBObject user = new BasicDBObject("user", new BasicDBObject("$exists", true));
  
          BasicDBObject parent = new BasicDBObject("parent", new BasicDBObject("$exists", true));
  
          BasicDBObject car = new BasicDBObject();
          parentMatch.put("car.id", mId);
          parentMatch.put("car.model", mModel);
  
          BasicDBObject carMatched = new BasicDBObject();
          parentMatch.put("car.matched.id", mId);
          parentMatch.put("car.matched.model", mModel);
  
          BasicDBList or1 = new BasicDBList();
          or.add(user);
          or.add(parent);
  
          BasicDBList or2 = new BasicDBList();
          or.add(car);
          or.add(carMatched);
  
          queryBuidlerType.add("$or", or1).add("$or", or2);
  
          DBObject queryType = queryBuidlerType.get();
      }
  }
  </code></pre>