|
@@ -287,10 +287,16 @@ class MongodbHandler:
|
|
|
|
|
|
except Exception as error:
|
|
|
self._log.log_and_raise_error(('An error occured trying to query data from {}, with query {}: {}:{}. \nError:{}').format(collection_name, attribute, comparison_operator, attribute_value, error))
|
|
|
- if return_as_dataframe:
|
|
|
- return self.convert_mongo_data_into_dataframe(data, index, collection_name)
|
|
|
+ return None
|
|
|
+
|
|
|
+ if len(list(data))> 0:
|
|
|
+ if return_as_dataframe:
|
|
|
+ return self.convert_mongo_data_into_dataframe(data, index, collection_name)
|
|
|
+ else:
|
|
|
+ return data
|
|
|
else:
|
|
|
- return data
|
|
|
+ self._log.warning(('No data for the query was found').format())
|
|
|
+ return None
|
|
|
|
|
|
def aggregate_data_and_generate_dataframe(self, collection_name: str, aggregation_pipeline: list, index: str = None):
|
|
|
|
|
@@ -298,6 +304,7 @@ class MongodbHandler:
|
|
|
data = self._database[collection_name].aggregate(pipeline=aggregation_pipeline, allowDiskUse=True)
|
|
|
except Exception as error:
|
|
|
self._log.log_and_raise_error(('A problem occured when aggregating the collection {} with the pipeline {}. \nError: {}').format(collection_name, aggregation_pipeline, error))
|
|
|
+ return None
|
|
|
|
|
|
return self.convert_mongo_data_into_dataframe(data, index, collection_name)
|
|
|
|
|
@@ -316,6 +323,7 @@ class MongodbHandler:
|
|
|
return df
|
|
|
else:
|
|
|
self._log.warning(('No data for the query was found').format())
|
|
|
+ return None
|
|
|
except Exception as error:
|
|
|
self._log.log_and_raise_error(('An error occured trying to convert mongo data into pd.Dataframe. \nError: {} ').format(error))
|
|
|
|