|
@@ -284,9 +284,12 @@ class MongodbHandler:
|
|
|
|
|
|
try:
|
|
try:
|
|
if attribute == None or attribute_value == None:
|
|
if attribute == None or attribute_value == None:
|
|
- data = self._database[collection_name].find({},return_values)
|
|
|
|
|
|
+ query = {}
|
|
|
|
+ data = self._database[collection_name].find(query,return_values)
|
|
|
|
+
|
|
else:
|
|
else:
|
|
- data = self._database[collection_name].find({attribute: {comparison_operator: attribute_value}}, return_values)
|
|
|
|
|
|
+ query = {attribute: {comparison_operator: attribute_value}}
|
|
|
|
+ data = self._database[collection_name].find(query, return_values)
|
|
|
|
|
|
except Exception as error:
|
|
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))
|
|
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))
|
|
@@ -332,30 +335,28 @@ class MongodbHandler:
|
|
except Exception as error:
|
|
except Exception as error:
|
|
self._log.log_and_raise_error(('An error occured trying to convert mongo data into pd.Dataframe. \nError: {} ').format(error))
|
|
self._log.log_and_raise_error(('An error occured trying to convert mongo data into pd.Dataframe. \nError: {} ').format(error))
|
|
'''
|
|
'''
|
|
- if data.collection.count_documents(query) != 0:
|
|
|
|
- frames = []
|
|
|
|
- records = []
|
|
|
|
- for iteration, value in enumerate(data):
|
|
|
|
|
|
+
|
|
|
|
+ frames = []
|
|
|
|
+ records = []
|
|
|
|
+ for iteration, value in enumerate(data):
|
|
|
|
|
|
- records.append(value)
|
|
|
|
- if iteration % chunksize == 0:
|
|
|
|
- frames.append(pd.DataFrame(records))
|
|
|
|
- records = []
|
|
|
|
-
|
|
|
|
- if records:
|
|
|
|
|
|
+ records.append(value)
|
|
|
|
+ if iteration % chunksize == 0:
|
|
frames.append(pd.DataFrame(records))
|
|
frames.append(pd.DataFrame(records))
|
|
- return_df = pd.concat(frames, axis=0, sort=False)
|
|
|
|
|
|
+ records = []
|
|
|
|
|
|
- if index is not None:
|
|
|
|
- return_df.set_index(index, inplace=True)
|
|
|
|
|
|
+ if records:
|
|
|
|
+ frames.append(pd.DataFrame(records))
|
|
|
|
+ return_df = pd.concat(frames, axis=0, sort=False)
|
|
|
|
|
|
- self._log.info(('{} Rows were fetched from {}. DataFrame conversion is done, took {} seconds').format(len(return_df.index), collection_name if collection_name is not None else 'the database', time.time()-start_time))
|
|
|
|
-
|
|
|
|
- return return_df
|
|
|
|
|
|
+ if index is not None:
|
|
|
|
+ return_df.set_index(index, inplace=True)
|
|
|
|
|
|
- else:
|
|
|
|
- self._log.warning('No data for the query was found when trying to create the dataframe')
|
|
|
|
- return None
|
|
|
|
|
|
+ self._log.info(('{} Rows were fetched from {}. DataFrame conversion is done, took {} seconds').format(len(return_df.index), collection_name if collection_name is not None else 'the database', time.time()-start_time))
|
|
|
|
+
|
|
|
|
+ return return_df
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
#def update_data_in_collection(self, query_label: str, query_value: str, update_label:str, update_value: str, collection_name:str):
|
|
#def update_data_in_collection(self, query_label: str, query_value: str, update_label:str, update_value: str, collection_name:str):
|