Browse Source

Searching for bug

ogert 4 years ago
parent
commit
855ef31527
1 changed files with 8 additions and 8 deletions
  1. 8 8
      cdplib/db_handlers/MongodbHandler.py

+ 8 - 8
cdplib/db_handlers/MongodbHandler.py

@@ -450,18 +450,18 @@ class MongodbHandler:
                 query = {attribute: {comparison_operator: attribute_value}}
                 query = {attribute: {comparison_operator: attribute_value}}
                 data = self._database[collection_name].find(query, {'_id': return_id}).sort(sort_label, direction).limit(limit)
                 data = self._database[collection_name].find(query, {'_id': return_id}).sort(sort_label, direction).limit(limit)
 
 
-            print('THIS IS THE DATA', list(data))
-            if data.collection.count_documents(query) == 0:
-                self._log.warning('No data was found for the query')
-                return None
-
         except Exception as error:
         except Exception as error:
             self._log.log_and_raise_error(('An error occured trying to query data from {}, \nError:{}').format(collection_name, error))
             self._log.log_and_raise_error(('An error occured trying to query data from {}, \nError:{}').format(collection_name, error))
 
 
-        if return_as_dataframe:
-            return self.convert_mongo_data_into_dataframe(data, index, collection_name)
+        if data.collection.count_documents(query) != 0:
+            if return_as_dataframe:
+                return self.convert_mongo_data_into_dataframe(data, index, collection_name)
+            else:
+                print('THIS IS THE DATA', list(data))
+                return data
         else:
         else:
-            return data
+            self._log.warning('No data was found for the query')
+            return None
 
 
     def update_data_in_collection(self, update_label:str, update_value: str, collection_name:str, query_label: str = None, query_value: str = None, create_if_not_exist: bool = True, find_query: dict = None, update_many: bool = False):
     def update_data_in_collection(self, update_label:str, update_value: str, collection_name:str, query_label: str = None, query_value: str = None, create_if_not_exist: bool = True, find_query: dict = None, update_many: bool = False):