If I have a document like this
{
    "_id" : "word",
    "nextWords" : {
        "x" : 3,
        "y" : 2,
        "z" : 1,
        "h" : 1,
        "n" : 10
    }
}
and I want to return the objects in "nextWords" sorted in a descending order.
Can I do that either in MongoDB Shell or Java?
Edit: I want "nextWords" sorted in a descending order according to its value, so the expected output is:
{
    "n" : 10
    "x" : 3,
    "y" : 2,
    "z" : 1,
    "h" : 1,
}
 
     
    