I have this example MongoDB entry in a users
DB:
{
_id: xxx,
name: "name",
files:[{
fileName: "test",
size: 50
},
{
fileName: "test2",
size: 44
},
{
fileName: "test3",
size: 120
}
]
}
And I'm trying to use Pymongo to sort the files by size.
How can I sort the dictionaries , using the aggregate
command? In other words, I want it to output this, in this case, in descending order:
[
{
fileName: "test3",
size: 120
},
{
fileName: "test",
size: 50
},
{
fileName: "test2",
size: 44
}
]
I can't find a way to get just the array itself and turn it into a Python list, so I can then sort it outside of using the Pymongo library, which is why I'm looking into using the Pymongo library to do the job.