This is stemming from an example that was provided at how to sort array inside collection record in mongoDB
> alit=[{a:16},{a:15},{a:14},{a:13},{a:12},{a:11},{a:10},{a:9},{a:8},{a:7},{a:6},{a:5},{a:4},{a:3},{a:2},{a:1},{a:0}]
> alit.sort(function(a,b) {return a.a>b.a } )
[ { "a":8 }, { "a":0 }, { "a":7 }, { "a":14 }, { "a":12 }, { "a":11 }, { "a":10 }, { "a":9 }, { "a":1 }, { "a":13 }, { "a":6 }, { "a":5 }, { "a":4 }, { "a":3 }, { "a":2 }, { "a":15 }, { "a":16 } ]
>
Note that if I execute this same line more times it gets progressively sorted more and more, it's as if this was executing a quicksort but with only two levels of recursion each time. Can anyone explain what I'm doing wrong and how to define a custom order that works in one sweep?