Support for sorting in query API

This commit is contained in:
Zaid Abdulla authored and root committed 2013-04-07 11:43:37 +03:00
1 parent 3f45c7e887
commit 8a26ea5111
1 file changed
+9
+9
View File
@@ -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?