title: Converting Mongo aggregate query into java objects
body: <p>I am trying to convert a mongo aggregate query into java objects. When I am running the query in RoboMongo (tool), I get the result but converting into java objects gives empty results.</p>
  
  <p><strong>Mongo Query:</strong></p>
  
  <pre><code>db.getCollection('wb_physicians').aggregate([
      { 
          $match: { 
              $and: [ 
                  { "product.mpoCode": "VA001"}, 
                  { "product.npoCode": { $exists: true } }
              ] 
          }
      },
      { 
          "$project" : { 
              "product.specialties.code": 1, 
              "providerId": 1,
              "product.code": 1, 
              "_id" : 0
          }
      }, 
      { "$unwind" : "$product.specialties" },
      { 
          "$group" : { 
              "_id" : { 
                  "providerId": "$providerId" , 
                  "productCode": "$product.code"
              }, 
              "specialityCodeList": { "$addToSet": "$product.specialties.code" }
          }
      }
  ])
  </code></pre>
  
  <p><strong>Java Code:</strong></p>
  
  <pre><code>private static AggregationOutput findProviderandSpecialty(DBCollection collection) {
      DBObject match =  new BasicDBObject("$match" , 
          new BasicDBObject("$and", Arrays.asList(
              new BasicDBObject("product.mpoCode" , "VA001").append("product.npoCode", "$exists: true")
          ))
      );
  
      DBObject project =  new BasicDBObject("$project" , 
          new BasicDBObject("product.specialties.code" , 1)
              .append("providerId" , 1)
              .append("product.code", 1)
              .append("_id", 0)
      );  
  
      DBObject unwind = new BasicDBObject("$unwind" , "$product.specialties");
  
      DBObject group = new BasicDBObject("$group",
          new BasicDBObject("_id", new BasicDBObject("providerId" , "$providerId"))
              .append("specialityCodeList", 
                  new BasicDBObject("$addToSet", "$product.specialties.code")
              )
      );
  
      AggregationOutput output = collection.aggregate(match,project,unwind,group);    
  
      return output;
  }   
  </code></pre>
  
  <p>Could you please help me where I made the wrong mapping?</p>