title: How to use mongodb lookup with group and calculate total
body: <p>I have two collections</p>
  
  <p>1.Product collection==></p>
  
  <pre><code>/* 1 */
  {
      "_id" : 154,
      "name" : "Chocolate Heaven",
      "price" : 7
  }
  
  /* 2 */
  {
      "_id" : 155,
      "name" : "Tasty Lemons",
      "price" : 8
  }
  
  /* 3 */
  {
      "_id" : 156,
      "name" : "Vanilla Dreams",
      "price" : 9
  }
  </code></pre>
  
  <p>2.Order collection==></p>
  
  <pre><code>/* 1 */
  {
      "_id" : 1,
      "product_id" : 154,
      "quantity" : 10
  }
  
  /* 2 */
  {
      "_id" : 2,
      "product_id" : 155,
      "quantity" : 3
  }
  
  /* 3 */
  {
      "_id" : 3,
      "product_id" : 156,
      "quantity" : 6
  }
  
  /* 4 */
  {
      "_id" : 4,
      "product_id" : 154,
      "quantity" : 1
  }
  </code></pre>
  
  <p>I am expecting an out put for a product what is the total price using mongodb</p>
  
  <p>156         Vanilla Dreams          9           6           54</p>
  
  <pre><code>db.getCollection('order').aggregate([
          {$group : {_id :{ product_id : "$product_id"}, sellCount : { $sum : "$quantity"}}},
          {$lookup : { from : 'product',localField : '_id.product_id' , foreignField :'_id',as: 'prodDetails' }},
          {$match: {prodDetails: {$ne: []}}}
  ]);
  </code></pre>
  
  <ol>
  <li>could you help me figure out the correct query.</li>
  <li>How to create view for this out put</li>
  </ol>