Skip to content

Commit

Permalink
Merge pull request #487 from erans/master
Browse files Browse the repository at this point in the history
Fix: Support newer as well as older PyMongo versions
  • Loading branch information
arikfr committed Jul 14, 2015
2 parents d3bb581 + 912bbc1 commit 5636cec
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,16 @@ def run_query(self, query):

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

# Backwards compatibility with older pymongo versions.
#
# Older pymongo version would return a dictionary from an aggregate command.
# The dict would contain a "result" key which would hold the cursor.
# Newer ones return pymongo.command_cursor.CommandCursor.
if isinstance(r, dict):
cursor = r["result"]
else:
cursor = r

for r in cursor:
for k in r:
Expand Down

0 comments on commit 5636cec

Please sign in to comment.