0

I have this result of a mongodb query.

{
    "zen": "blah",
    "den": 123,
    "ben": "blah",
    "cen": false,
    "xen": 29
}

How can I get the result lexicographically sorted by keys and not the value of keys?

I want the result like this:

{
    "ben": "blah",
    "cen": false,
    "den": 123,
    "xen": 29
    "zen": "blah",
}

Is it possible?

styvane
  • 49,879
  • 15
  • 119
  • 132
Mohammad Yusuf
  • 13,560
  • 7
  • 38
  • 68
  • This doesn't make any sense. And why do you need this. You should read [Sorting a JavaScript object by property name](http://stackoverflow.com/questions/1359761/sorting-a-javascript-object-by-property-name) or [Sort JavaScript object by key](http://stackoverflow.com/questions/5467129/sort-javascript-object-by-key) – styvane Dec 31 '15 at 11:10
  • You are right its not of that much use. But sometimes i'd like to look for some key value pairs in database queries. I can do a ctrl+f to find it but if I display them in lexicographical order than perhaps it might be easier to find the key value pairs. I have a big document in mongodb and I query in robomongo and mongo studio. – Mohammad Yusuf Jan 01 '16 at 06:58

0 Answers0