title: How could I sort the items of a array and update to the original document
body: <p>I want to sort the array <code>records</code> and remove the <code>"               "</code>, <code>"     "</code> items only containing white space.</p>
  
  <p>How to get it with aggregation.</p>
  
  <p>This is my rough idea, but not working</p>
  
  <pre><code>pipeline = [
    {'$unwind': '$records'}
    { '$sort': 
        "records.date": 1 
    }
  ]  
  db[source_collection].runCommand('aggregate',
    pipeline: pipeline
    allowDiskUse: true)    
  </code></pre>
  
  <p>Sample document format</p>
  
  <pre><code>{
    "_id": "0005dc158e68b0a2e4f2a8d96ca733f1",
    "records": [
      {
        "date": new Date("2012-12-04T08:00:00+0800"),
        "items": [
          "               ",
          "4659           ",
          "463            "
        ]
      },
      {
        "date": new Date("2012-12-01T08:00:00+0800"),
        "items": [
          "               ",
          "4658           "
        ]
      },
      {
        "date": new Date("2012-10-18T08:00:00+0800"),
        "items": [
          "               ",
          "78900          "
        ]
      },
      {
        "date": new Date("2012-08-07T08:00:00+0800"),
        "items": [
          "               ",
          "5230           "
        ]
      }
    ],
    "gender": "F",
    "birthday": new Date("1990-01-01T08:00:00+0800"),
    "birthday_type": "D"
  }
  </code></pre>