tdegrunt/mongodb-rest — Issue #23: Reverse sort order
Author: Filirom1
Created: 2011-11-28 17:15:34+00:00
State: open

In the following exemple, I try to sort the result with a desc order

$ curl -d '{ "A1" : 201 }' -H "Content-Type: application/json" http://localhost:3000/test/example1
$ curl -d '{ "A1" : 3 }' -H "Content-Type: application/json" http://localhost:3000/test/example1
$ curl -d '{ "A1" : 307 }' -H "Content-Type: application/json" http://localhost:3000/test/example1

Sort asc (easy) :

$ curl http://localhost:3000/test/example1?sort=A1

[
{"A1":3,"_id":"4ed3aee8cc4fc51e1a000002"},
{"A1":201,"_id":"4ed3aedccc4fc51e1a000001"},
{"A1":307,"_id":"4ed3aeedcc4fc51e1a000003"}
]

But how can I do a desc sort:

I tried with:

> encodeURI("{A1:-1}")
'%7BA1:-1%7D'

$ curl http://localhost:3000/test/example1?sort=%7BA1:-1%7D

[
{"A1":3,"_id":"4ed3aee8cc4fc51e1a000002"},
{"A1":201,"_id":"4ed3aedccc4fc51e1a000001"},
{"A1":307,"_id":"4ed3aeedcc4fc51e1a000003"}
]