Skip to content

Commit

Permalink
Cleaner approach for _is_collection_a_view (#3113)
Browse files Browse the repository at this point in the history
* Fix collection fields retreival bug when Views are present in MongoDB

* fixing _is_collection_a_view function

* Update redash/query_runner/mongodb.py

Co-Authored-By: jodevsa <jodevsa@gmail.com>

* using options() instead of try/except on collstats  to detect if a collection  is a view
  • Loading branch information
jodevsa authored and arikfr committed Feb 21, 2019
1 parent 2a37cb3 commit 8679b87
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ def _merge_property_names(self, columns, document):
columns.append(property)

def _is_collection_a_view(self, db, collection_name):
try:
db.command('collstats', collection_name)
return False
except Exception:
if 'viewOn' in db[collection_name].options():
return True
else:
return False

def _get_collection_fields(self, db, collection_name):
# Since MongoDB is a document based database and each document doesn't have
Expand Down

0 comments on commit 8679b87

Please sign in to comment.