thohoh
11/1/2018 - 9:25 PM

Aggregate queries

// Get sum of a certain field across all the documents in a collection

db.getCollection('simple-arb').aggregate([
  { 
    $match: {
      closed: {
        $eq: true
      }    
    }
  }, {
    $group: {
      _id: null,
      total: {
        $sum: "$actualProfit"
      }
    }
  }
])