Skip to content

Commit

Permalink
Added backwards compatibility mode with older versions of PyMongo.
Browse files Browse the repository at this point in the history
It appears that older versions would return a dictionary from an aggregate operation that had the cursor inside the "result" key.
Newer versions return a new type of cursor called CommandCursor.
  • Loading branch information
erans committed Jul 14, 2015
1 parent 4a7c066 commit 912bbc1
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 912bbc1

Please sign in to comment.