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()?
Assuming an object is:
{ //document data,
array : [ {//subdocument data,
"key" : 185},
{//subdocument data,
"key" : 186},
{...}]
}
I have tried the following which does not work but I search for a simple similar option:
db.col.find().sort('array.key', pymongo.ASCENDING)
or should I do it with python sort?
for location in locations:
data['array'] = sorted(data['array'], key=lambda x: x['key'])