title: How can i add or & and Criteria clauses with in a single Query Object Mongodb Spring data
body: <p>I want to add or &amp; and clauses to my query object at the same time but i am keep getting te below error</p>
  
  <p>Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'null' criteria?</p>
  
  <p>For example</p>
  
  <pre><code>query.addCriteria(new Criteria().orOperator(Some Critera);
  
  
   query.addCriteria(new Criteria().andOperator(Some Critera);
  </code></pre>
  
  <p>Can anyone help me out on this?</p>
  
  <p><strong>Detail:</strong></p>
  
  <p>Actually i am try to parse the following json and building dynamic query based on that parsed json</p>
  
  <pre><code>{
    "query":{
  
      "where":[{
  
                "or":[
                {
                   "fieldName":"address1","fieldValue":"Dummy address1",
  
                   "operator":"equal"
                }
  
              ],
              "and":[{
                    "fieldName":"version","fieldValue":"1",
  
                   "operator":"equal"
  
               }]
             }
          ]
     }
  }
  </code></pre>
  
  <p>So you can suggest me other ways to parse that json into Mongodb query using mongoTemplate spring data</p>
  
  <p>here is my parsing code</p>
  
  <pre><code>if(null != eventSearch.getQuery())
          {
  
              if(null != eventSearch.getQuery().getWhere() &amp;&amp; eventSearch.getQuery().getWhere().size() &gt; 0)
              {
  
                  for (Where whereClause : eventSearch.getQuery().getWhere()) {
  
                        if(null != whereClause.getOr() &amp;&amp; whereClause.getOr().size() &gt; 0){
  
                            List&lt;org.springframework.data.mongodb.core.query.Criteria&gt; orCriterias = new ArrayList&lt;org.springframework.data.mongodb.core.query.Criteria&gt;(whereClause.getOr().size());
  
                            for (Field field: whereClause.getOr()) {
  
                                if(field.getOperator().equalsIgnoreCase(QueryOperator.IS))
                                {
                                  orCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).is(field.getFieldValue()));
  
                                }else if(field.getOperator().equalsIgnoreCase(QueryOperator.LT)){
  
                                  orCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).lt(field.getFieldValue()));
                                } 
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.GT)){
  
                                    orCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).gt(field.getFieldValue()));
                                } 
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.LTE)){
  
                                    orCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).lte(field.getFieldValue()));
                                 }
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.GTE)){
  
                                    orCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).gte(field.getFieldValue()));
                                 }
                            } 
  
                            query.addCriteria(new org.springframework.data.mongodb.core.query.Criteria().orOperator(orCriterias.toArray(new org.springframework.data.mongodb.core.query.Criteria[whereClause.getOr().size()])));
                        }
  
                        if(null != whereClause.getAnd() &amp;&amp; whereClause.getAnd().size() &gt; 0){
  
                            List&lt;org.springframework.data.mongodb.core.query.Criteria&gt; andCriterias = new ArrayList&lt;org.springframework.data.mongodb.core.query.Criteria&gt;(whereClause.getAnd().size());
  
                            for (Field field: whereClause.getAnd()) {
  
                                if(field.getOperator().equalsIgnoreCase(QueryOperator.IS))
                                {
                                    andCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).is(field.getFieldValue()));
  
                                }else if(field.getOperator().equalsIgnoreCase(QueryOperator.LT)){
  
                                    andCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).lt(field.getFieldValue()));
                                } 
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.GT)){
  
                                    andCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).gt(field.getFieldValue()));
                                } 
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.LTE)){
  
                                    andCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).lte(field.getFieldValue()));
                                 }
                                else if(field.getOperator().equalsIgnoreCase(QueryOperator.GTE)){
  
                                    andCriterias.add(org.springframework.data.mongodb.core.query.Criteria.where(field.getFieldName()).gte(field.getFieldValue()));
                                 }
                            } 
                            //Getting exception at this line
                            query.addCriteria(new org.springframework.data.mongodb.core.query.Criteria().andOperator(andCriterias.toArray(new org.springframework.data.mongodb.core.query.Criteria[whereClause.getAnd().size()])));
                        }
  }}
  </code></pre>