title: Is it possible to sort a mongodb array of subdocuments straight with pymongo?
body: <p>I don't need to sort the returned documents (objects) but an array each of them based on a nested value.Is it something doable with pymongo.sort()?</p>
  
  <p>Assuming an object is:</p>
  
  <pre><code>{ //document data,
    array : [ {//subdocument data,
               "key" : 185},
               {//subdocument data,
               "key" : 186},
               {...}]
  }
  </code></pre>
  
  <p>I have tried the following which does not work but I search for a simple similar option:</p>
  
  <pre><code>db.col.find().sort('array.key', pymongo.ASCENDING)
  </code></pre>
  
  <p>or should I do it with python sort?</p>
  
  <pre><code>for location in locations:
      data['array'] = sorted(data['array'], key=lambda x: x['key'])
  </code></pre>