Skip to content

Commit

Permalink
Merge pull request #349 from erans/master
Browse files Browse the repository at this point in the history
Minor bug fixes + supprot for limit and skip in simple query
  • Loading branch information
arikfr committed Jan 18, 2015
2 parents dc0f9a6 + 2dbcd88 commit 0d35ec7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions redash/data/query_runner_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ def query_runner(query):
if "sort" in query_data and query_data["sort"]:
s = []
for field in query_data["sort"]:
for k in field:
s.append((k, field[k]))
s.append((field["name"], field["direction"]))

if "fields" in query_data:
f = query_data["fields"]
Expand All @@ -192,11 +191,18 @@ def query_runner(query):
json_data = None

cursor = None
if q:
if q or (not q and not aggregate):
if s:
cursor = db[collection].find(q, f).sort(s)
else:
cursor = db[collection].find(q, f)

if "skip" in query_data:
cursor = cursor.skip(query_data["skip"])

if "limit" in query_data:
cursor = cursor.limit(query_data["limit"])

elif aggregate:
r = db[collection].aggregate(aggregate)
cursor = r["result"]
Expand Down

0 comments on commit 0d35ec7

Please sign in to comment.