title: How to unwind two arrays in mongoquery
body: <p>I have a collection like this in mongodb:</p>
  
  <pre><code>{
  "_id" : ObjectId("5490a00879dc6a138dcefb0f"),
  "Date" : 20141012,
  "Type" : "Twitter",
  "Entities" : [ 
      {
          "ID" : 2,
          "Name" : "test1",
          "Sentiment" : {
              "Value" : 0.1,
              "Neutral" : 12
          }
       }
  ],
  "Topics" : [ 
      {
          "ID" : 1,
          "Name" : "Test2",
          "Sentiment" : {
              "Value" : 0.5,
              "Neutral" : 1
          }
      }
  ]
  }
  </code></pre>
  
  <p>Now I need to unwind both array Topics and Entities and then I want to group by on date and sum all values for sentiment so I did it as follow:</p>
  
  <pre><code>    DBObject unwind = new BasicDBObject("$unwind", "$Entities"); 
      unwind.put("$unwind", "$Topics");
      collectionG = db.getCollection("GraphDataCollection");
      DBObject groupFields = new BasicDBObject( "_id", "$Date");
      groupFields.put("value", new BasicDBObject( "$sum", "$Entities.Sentiment.Value"));
      DBObject groupBy = new BasicDBObject("$group", groupFields );
      AggregationOutput output = collectionG.aggregate(where,unwind, groupBy);
  </code></pre>
  
  <p>Now the problem is that for sum of vaues of sentiment just 0 returned but If I remove the following line :</p>
  
  <pre><code>    unwind.put("$unwind", "$Topics");
  </code></pre>
  
  <p>it works correctly so my problem is how to unwind two arrays with one aggregation?</p>
  
  <p>Update : </p>
  
  <p>I changed my code as follow :</p>
  
  <pre><code>DBObject unwind = new BasicDBObject("$unwind", "$Entities"); // "$unwind" converts object with array into many duplicate objects, each with one from array
      DBObject unwindT = new BasicDBObject("$unwind", "$Topics"); // "$unwind" converts object with array into many duplicate objects, each with one from array
      collectionG = db.getCollection("GraphDataCollection");
      DBObject groupFields = new BasicDBObject( "_id", "$Date");
     groupFields.put("value", new BasicDBObject( "$sum", "$Entities.Sentiment.Value"));
      groupFields.put("value1", new BasicDBObject( "$sum", "$Topics.Sentiment.Value"));
      DBObject groupBy = new BasicDBObject("$group", groupFields );
      List&lt;DBObject&gt; pipeline = Arrays.asList(unwind, unwindT);
      DBObject sort = new BasicDBObject("$sort", new BasicDBObject("_id", 1));
      AggregationOutput output = collectionG.aggregate(where,unwind,unwindT, groupBy,sort);
  </code></pre>
  
  <p>but the problem is as soon as I add the following line :</p>
  
  <pre><code>groupFields.put("value1", new BasicDBObject( "$sum", "$Topics.Sentiment.Value"));
  </code></pre>
  
  <p>the numbers for value1 and value that are returned is not correct and I think I am not doing unwinding correctly. can anyone help ?</p>