title: MongoDB Aggregate query in Java
body: <p>I am new to Java and like to know how to build mongoDB query in java.</p>
  
  <pre><code>    db.coll.aggregate(
         { $match : {
          loc: {
              "$ref" : "location", 
              "$id" : ObjectId("4fe69610e7e9fa378c3c802e")
          }
      }},
         { $unwind : "$ActivityList" },
     { $match : {
         'ActivityList.user': {
              "$ref" : "userProfile",
              "$id" : ObjectId("4fdeafe1de26fd298262bb82")
          } 
      }},
      { $group : {
          _id : "$ActivityList.type",
          latest: { $max: '$ActivityList.timestamp' }
      }}
  );
  </code></pre>
  
  <p>Thanks for your help.</p>