title: MongoDB merge related collection item count with other collection results
body: <p>I'm new to mongodb and trying figure out how to efficiently query on each item within a collection.</p>
  
  <p>I have <code>projects</code> collection &amp; <code>tasks</code> collections</p>
  
  <pre><code>//projects
  {
     _id: ObjectId(),
     name: String
  }
  //tasks
  {
     _id: ObjectId(),
     projectId: ObjectId(), //reference project id
     completed: Bool
  }
  </code></pre>
  
  <p>I would like to get all projects and then count of <code>completed</code> and <code>incomplete</code> tasks of each project</p>
  
  <pre><code>db.projects.find({})...
  //perhaps something similar in output
  [
   {
     _id: ObjectId(), //projectId
     name: String
     completed: Number,
     incomplete: Number
   }
  ]
  </code></pre>
  
  <p>I'm using mongoose as ORM. I don't know if this is possible in mongoose or even native mongodb query. Appreciate any help. Thanks!</p>