title: MongoDB Lookup with Conditions
body: <p>Sorry for what I'm sure is a newbie question but after a couple dais I'm at a total loss on how to approach this.</p>
  
  <p>I've currently two collections, one being <code>orders</code> and another one being <code>offers</code>. Offers are basically quote offers to the orders (linked by <code>_id&lt;-&gt;orderId</code>).</p>
  
  <p>Example of Orders collection:</p>
  
  <pre><code>{ 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : true, 
      "updated" : ISODate("2017-06-02T08:20:47.772+0000"), 
      "created" : ISODate("2017-06-02T08:10:51.401+0000"), 
      "name" : "Sicherungsbolzen",
      "state" : "active"
  }
  { 
      "_id" : ObjectId("59311ee2a0ea6500113df5d8"), 
      "deleted" : false, 
      "updated" : ISODate("2017-06-02T08:16:34.911+0000"), 
      "created" : ISODate("2017-06-02T08:16:34.911+0000"), 
      "name" : "Mitnehmerstein SK50 ",
      "state" : "active"
  }
  </code></pre>
  
  <p>Example of Quotes collection:</p>
  
  <pre><code>{ 
      "_id" : ObjectId("59311ee2a0ea6500113df5d8"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T13:18:34.872+0000"), 
      "created" : ISODate("2019-11-08T06:54:14.072+0000"), 
      "orderId" : ObjectId("5db6c679d8499800286ff64a"), 
      "proposal" : {
          "price" : NumberInt(19800), 
          "currency" : "CUR51", 
          "deliveryDate" : NumberInt(21), 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T10:11:48.112+0000"), 
      "created" : ISODate("2019-10-29T11:31:05.980+0000"), 
      "orderId" : ObjectId("5db74034d849980028701a95"), 
      "proposal" : {
          "price" : 31.78, 
          "currency" : "CUR48", 
          "deliveryDate" : NumberInt(1), 
          "files" : [
  
          ]
      }
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T08:37:04.354+0000"), 
      "created" : ISODate("2019-11-08T08:37:04.354+0000"), 
      "orderId" : ObjectId("5db80b84ed142100263a5088"), 
      "proposal" : {
          "price" : NumberInt(2345), 
          "deliveryDate" : NumberInt(18), 
          "currency" : "CUR48", 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-15T14:32:15.958+0000"), 
      "created" : ISODate("2019-11-06T14:42:23.492+0000"), 
      "orderId" : ObjectId("5dc03382751ecc002899e1fa"), 
      "proposal" : {
          "price" : NumberInt(86400), 
          "currency" : "CUR48", 
          "deliveryDate" : NumberInt(90), 
          "files" : [
  
          ]
      }
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-22T23:10:07.056+0000"), 
      "created" : ISODate("2019-11-06T20:09:20.706+0000"), 
      "orderId" : ObjectId("5dc03382751ecc002899e1fa"), 
      "proposal" : {
          "price" : NumberInt(57419), 
          "currency" : "CUR48", 
          "deliveryDate" : NumberInt(27), 
          "files" : [
  
          ]
      }
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T08:52:18.910+0000"), 
      "created" : ISODate("2019-11-08T08:52:18.910+0000"), 
      "orderId" : ObjectId("5dc05c0a751ecc00289a0187"), 
      "proposal" : {
          "price" : NumberInt(9900), 
          "deliveryDate" : NumberInt(35), 
          "currency" : "CUR48", 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311d8ba0ea6500113df5d6"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T09:39:12.383+0000"), 
      "created" : ISODate("2019-11-08T09:39:12.383+0000"), 
      "orderId" : ObjectId("5dc47fb10a1f7c00262763e3"), 
      "proposal" : {
          "price" : NumberInt(79), 
          "deliveryDate" : NumberInt(7), 
          "currency" : "CUR48", 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311ee2a0ea6500113df5d8"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T09:45:41.392+0000"), 
      "created" : ISODate("2019-11-08T09:45:41.392+0000"), 
      "orderId" : ObjectId("5dc480ab751ecc00289b32c7"), 
      "proposal" : {
          "price" : NumberInt(240), 
          "deliveryDate" : NumberInt(7), 
          "currency" : "CUR48", 
          "message" : "Hi Alex, I saw you put several RFQs in the platform,attached quotation for reference.If you have any question,please contact me at engineer07@top-rp.cn. Looking forward to your feedback.By the way,may I know your email?\n\nRebecca", 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311ee2a0ea6500113df5d8"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T09:43:29.928+0000"), 
      "created" : ISODate("2019-11-08T09:43:29.928+0000"), 
      "orderId" : ObjectId("5dc482430a1f7c00262763e6"), 
      "proposal" : {
          "price" : NumberInt(390), 
          "deliveryDate" : NumberInt(7), 
          "currency" : "CUR48", 
          "message" : "Hi Alex, I saw you put several RFQs in the platform,attached quotation for reference.If you have any question,please contact me at engineer07@top-rp.cn. Looking forward to your feedback.By the way,may I know your email?\n\nRebecca", 
          "files" : [
  
          ]
      }, 
  }
  { 
      "_id" : ObjectId("59311ee2a0ea6500113df5d8"), 
      "deleted" : false, 
      "updated" : ISODate("2019-11-08T06:56:15.346+0000"), 
      "created" : ISODate("2019-11-08T06:56:15.346+0000"), 
      "orderId" : ObjectId("5dc4843b0a1f7c00262763ed"), 
      "proposal" : {
          "price" : NumberInt(3), 
          "deliveryDate" : NumberInt(7), 
          "currency" : "CUR48", 
          "files" : [
  
          ]
      }, 
  }
  </code></pre>
  
  <p><strong>I've a main goal:</strong>
  Export an excel that will display the "average" of prices per quote. That is, if an order received 3 quotes (20, 30, 40) it will be: OrderID, 30 (being 30 the average of 20, 30, 40).</p>
  
  <p>In this case, having 2 orders (59311d8ba0ea6500113df5d6 and 59311ee2a0ea6500113df5d8), it must display:</p>
  
  <pre><code>ORDERID, AVERAGE OF PRICE
  
  59311ee2a0ea6500113df5d8, 99 (average all the proposal.price for each quote of this order)
  59311d8ba0ea6500113df5d6, 129 (average all the proposal.price for each quote of this order)
  </code></pre>
  
  <p>Any hints, tips, help?</p>
  
  <p>Thanks in advance</p>