Closed Filirom1 closed 6 years ago
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":201,"_id":"4ed3aedccc4fc51e1a000001"}, {"A1":3,"_id":"4ed3aee8cc4fc51e1a000002"}, {"A1":307,"_id":"4ed3aeedcc4fc51e1a000003"} ]
But it doesn't work.
Possibly this commit can fix the issue: https://github.com/tdegrunt/mongodb-rest/pull/25
This can be done with ?sort={"A1":1} for ASC order and ?sort={"A1":-1} for DESC order.
?sort={"A1":1}
?sort={"A1":-1}
In the following exemple, I try to sort the result with a desc order
Sort asc (easy) :
$ curl http://localhost:3000/test/example1?sort=A1
But how can I do a desc sort:
I tried with:
But it doesn't work.