title: MongoDB aggregate $group and $match with group result
body: <p>I have a collection as follows</p>
  
  <pre><code>{
  
      "_id" : ObjectId("553b2c740f12bb30f85bd41c"),
      "symbol" : "EUR/GBP",
      "order_id" : "PW_BarclaysTrades60530",
      "ticket_id" : "PW_BarclaysTrades.60530",
      "basketid" : "TESTBASKET-1428483828043",
      "date_sent" : ISODate("2015-04-07T18:30:00.000Z"),
      "destination" : "BarclaysTrades",
      "order_price" : 0.0000000000000000,
      "order_quantity" : 4000000.0000000000000000,
      "order_type" : 1.0000000000000000,
      "parent_quantity" : 250000000.0000000000000000,
      "time_sent" : "09:03:48",
      "side" : 1,
      "tif" : "0",
      "execution_id" : 88939,
      "date_recvd" : ISODate("2015-04-07T18:30:00.000Z"),
      "exe_quantity" : 50000.0000000000000000,
      "time_recvd" : "09:03:48",
      "execution_price" : 2.5000000000000000,
      "execution_type" : 1
  }
  </code></pre>
  
  <p>I would like to get the documents whose execution_price greater than  average(execution_price) for each destination in the collection</p>
  
  <p>Trying to aggregate as follows:</p>
  
  <pre><code>db.orders_by_symbol.aggregate( [
  { $limit:300000 },
  { $match:{ destination: "PAPER" } },
  { $group:{_id:{Destination:"$destination"},avg_exec_price:  
                {$avg:"$execution_price"} ,"data":{"$push": "$$ROOT"}}},
  {$unwind:"$data"},
  {$match:{execution_price:{$ne: "$avg_exec_price"}}},
  {$project:{_id:0,symbol:"$data.symbol",destination:"$data.destination",
            execution_id:"$data.execution_id",
            exec_price:"$data.execution_price",
           avg_ex_price:"$avg_exec_price"}}], 
  {allowDiskUse:true})
  </code></pre>
  
  <p>Getting the following Result </p>
  
  <pre><code>{
  
      "result" : [ 
          {
              "symbol" : "EUR/GBP",
  
              "destination" : "PAPER",
              "execution_id" : 89109,
              "exec_price" : 6.5000000000000000,
              "avg_ex_price" : 95.0747920857049140
          }, 
          {
              "symbol" : "EUR/GBP",
              "destination" : "PAPER",
              "execution_id" : 89110,
              "exec_price" : 6.0000000000000000,
              "avg_ex_price" : 95.0747920857049140
          }, 
          {
              "symbol" : "EUR/GBP",
              "destination" : "PAPER",
              "execution_id" : 89111,
              "exec_price" : 6.5000000000000000,
              "avg_ex_price" : 95.0747920857049140
          }
  </code></pre>
  
  <p>But when I change the '$ne' operator with  '$gt' no result is being produced. Both exec_price and avg_ex_price are double datatype.Not sure why it is not working as expected.</p>