title: Mongoose Aggregation match an array of objectIds
body: <p>I have a schema that Looks like this </p>
  
  <pre><code>var Post = new mongoose.Schema({
      author: {
          type: mongoose.Schema.Types.ObjectId,
          ref: 'User'
      },
      created: {
          type: Date,
          Default: Date.now
      })
  </code></pre>
  
  <p>I have a User Table as well. I Have a array of user ids and i am trying to search the post table based on an array of user ids </p>
  
  <p>For Example </p>
  
  <pre><code>var userIds = ["575e96652473d2ab0ac51c1e","575e96652473d2ab0ac51c1d"] .... and so on 
  </code></pre>
  
  <p>I want to return all posts created by these users. And posts should be sorted by their creation date. Is there a way to group this post based on the user ids provided, basically match the posts for an individual user?</p>
  
  <p>The result I am trying to attain is something like this: </p>
  
  <pre><code> [{
      userAId : "56656.....",
      post : [postA, postB],
     },{ 
      userBId :"12345...", 
      post : [postA, postB]
  }]
  </code></pre>
  
  <p>How do I write this query?</p>
  
  <p>This is what I have so far </p>
  
  <pre><code>Post.aggregate([{
    // {"$unwind" : ""},
      // "$group": {
      //     _id: "$author",
      //     "created" : {"$sum" : 1 }
      // }
      "$match" : { author : id}
  }]).exec(function(error, data) {
    if(error){
      return console.log(error);
    }else{
      return console.log(data)
    }
  })
  
  
  
  {
      "_id" : ObjectId("575e95bc2473d2ab0ac51c1b"),
      "lastMod" : ISODate("2016-06-13T11:15:08.950Z"),
      "author" : ObjectId("575dac62ec13010678fe41cd"),
      "created" : ISODate("2016-06-13T11:15:08.947Z"),
      "type" : "photo",
      "end" : null,
      "commentCount" : 0,
      "viewCount" : 0,
      "likes" : 0,
      "tags" : [],
      "title" : "Today is a good day",
      "__v" : 0
  }
  </code></pre>