title: MongoDB agregation and comparing
body: <p>I need to write mongodb query that will agregate items by quantinty (orders collestion). After agregation, or with agregation, it should identify items that can't be supplied in stock collection, and return name of the person who made this order</p>
  
  <p>code of orders insert</p>
  
  <pre><code>db.orders.insertMany([
  {client:  {firstName: "John",lastName: "Smith" },orderedItems: [{ name: "itemA", qty: 5},{ name: "itemS", qty: 3}]},
  {client:  {firstName: "Jan",lastName: "Nowak" },orderedItems: [{ name: "itemA", qty: 56},{ name: "itemS", qty: 53}]},
  {client:  {firstName: "Klara",lastName: "Bolączka" },orderedItems: [{ name: "itemA", qty: 35},{ name: "itemS", qty: 23}]},
  {client:  {firstName: "Brajan",lastName: "Kowalski" },orderedItems: [{ name: "itemA", qty: 95},{ name: "itemS", qty: 13}]}
  ]);
  </code></pre>
  
  <p>code of stocks insert</p>
  
  <pre><code>db.stock.insertMany([
  { item: "itemA", qty: 40},
  { item: "itemS", qty: 113}  
  ]); 
  </code></pre>
  
  <p>Right now i got some mongoDB code, that just agregates orders</p>
  
  <pre><code>db.orders.aggregate([
  {$unwind: "$orderedItems"},
  {$group: { _id: "$orderedItems.name", total:{$sum: "$orderedItems.qty"}}}
  ]);
  </code></pre>
  
  <p>I tried to use lookup, but probably I'm doing something wrong.</p>
  
  <p>Could I get some sugestions, please?</p>