From 8a26ea511159e185d535bb41338fddd6eddbe0c5 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 7 Apr 2013 11:42:44 +0300 Subject: [PATCH] Support for sorting in query API --- api.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api.coffee b/api.coffee index 7bed34a..cee87fb 100644 --- a/api.coffee +++ b/api.coffee @@ -361,6 +361,15 @@ else projection[a] = 1 for a in v cur = collection.find(q, projection, {batchSize : 50}) + if urlParts.query.sort? + s = JSON.parse(querystring.unescape(urlParts.query.sort)) + sort = {} + for k,v of s + if config.ALIASES[k]? + sort[a] = v for a in config.ALIASES[k] + else + sort[k] = v + cur.sort(sort) cur.skip(parseInt(urlParts.query.skip)) if urlParts.query.skip? cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit?