title: Aggregation with update in mongoDB
body: <p>I've a collection with many similar structured document, two of the document looks like</p>
  
  <p>Input:</p>
  
  <pre><code>{ 
      "_id": ObjectId("525c22348771ebd7b179add8"), 
      "cust_id": "A1234", 
      "score": 500, 
      "status": "A"
      "clear": "No"
  }
  
  { 
      "_id": ObjectId("525c22348771ebd7b179add9"), 
      "cust_id": "A1234", 
      "score": 1600, 
      "status": "B"
      "clear": "No"
  }
  </code></pre>
  
  <p>By default the <code>clear</code> for all document is <code>"No"</code>,</p>
  
  <p>Req: I have to add the score of all documents with same <code>cust_id</code>, provided they belong to <code>status</code> <code>"A"</code> and <code>status</code> <code>"B"</code>. If the <code>score</code> exceeds <code>2000</code> then I have to update the <code>clear</code> attribute to <code>"Yes"</code> for all of the document with the same <code>cust_id</code>.</p>
  
  <p>Expected output:</p>
  
  <pre><code>{ 
      "_id": ObjectId("525c22348771ebd7b179add8"), 
      "cust_id": "A1234", 
      "score": 500, 
      "status": "A"
      "clear": "Yes"
  }
  
  {
      "_id": ObjectId("525c22348771ebd7b179add9"), 
      "cust_id": "A1234", 
      "score": 1600, 
      "status": "B"
      "clear": "Yes"
  }
  </code></pre>
  
  <p>Yes because 1600+500 = 2100, and 2100 > 2000.</p>
  
  <hr>
  
  <p>My Approach:
  I was only able to get the sum by aggregate function but failed at updating</p>
  
  <pre><code>db.aggregation.aggregate([
      {$match: {
          $or: [
              {status: 'A'},
              {status: 'B'}
          ]
      }},
      {$group: {
          _id: '$cust_id',
          total: {$sum: '$score'}
      }},
      {$match: {
          total: {$gt: 2000}
      }}
  ])
  </code></pre>
  
  <p>Please suggest me how do I proceed.</p>