title: MongoDB sorting by date as type String
body: <p>Can someone help me with the query for sorting an array by date in ascending order?
  I have tried the below query but the sorting is not happening as expected,</p>
  
  <pre><code>db.getCollection(xyz).aggregate([{
  
         $match: {
            "_id":{$in:[{"a" : "NA","b" : "HXYZ","c" : "12345","d" : "AA"}]}
                       }
                     },{
                         $sort: {'bal.date': 1}
                     },
  
                     { $project: {
              balances: { $slice: ["$bal",2]} 
  
                          }
  
               }
  
                    ])
  </code></pre>
  
  <p>My collection:</p>
  
  <pre><code>/* 1 */
  {
      "_id" : {
          "a" : "NA",
          "b" : "HXYZ",
          "c" : "12345",
          "d" : "AA"
      },
  
  
         "bal" : [
       {
              "type" : "E",
              "date" : "2015-08-02"
  
      },
  
      {
              "type" : "E",
              "date" : "2015-08-01"
  
  
      },
       {
              "type" : "E",
              "date" : "2015-07-07"
  
  
      }
  
   ]
   }
  </code></pre>
  
  <p>Please help me what is the problem in the above query.
  Thanks in advance.</p>