title: How to use "$match" and "$or" in mongo aggregation in java
body: <p>I'm trying to load the matched documents into a temporary collection using aggregation query. Actually, I'm able to load all the matched documents into the temporary collection of MongoDB but my java program is throwing Null pointer exception at the for loop.</p>
  
  <p>I'm totally stuck over here. May I know the reason for Null Pointer exception in this scenario . And can anyone please suggest me regarding the same ...  </p>
  
  <pre><code> Document query = {"$or":[{"roll":1,"joiningDate":{"$gte":ISODate("2017-04-11T00:00:00Z")}},{"roll":2,"joiningDate":{"$gte": ISODate("2017-03-17T00:00:00Z")}}]};
  
              Document match = new Document("$match",new Document("$or",query));
  
              Document out =new Document("$out","TempCol");
  
              System.out.println("Before Aggregation");
  
              AggregateIterable&lt;Document&gt; resultAgg = collection.aggregate(Arrays.asList(match,out));
  
              System.out.println("After aggregation");
  
              for (Document doc : resultAgg){
  
  
                      System.out.println("The result of aggregation match:-");
  
              }
  
              System.out.println("Completed");
  </code></pre>