Selaa lähdekoodia

changed query_and_insert method to aggregate_and_insert

tanja 4 vuotta sitten
vanhempi
commit
f5d97de516
1 muutettua tiedostoa jossa 14 lisäystä ja 8 poistoa
  1. 14 8
      cdplib/db_handlers/MongodbHandler.py

+ 14 - 8
cdplib/db_handlers/MongodbHandler.py

@@ -293,14 +293,20 @@ class MongodbHandler:
             else:
                 return data
 
-    def query_and_insert_into_collection(self,
+    def aggregate_and_insert_into_collection(self,
                                          input_collection_name: str,
                                          output_collection_name: str,
-                                         query: dict = None):
+                                         aggregation_pipeline: list = None):
         """
         """
-        self._database[output_collection_name].insert(
-                self._database[input_collection_name].find({}).toArray())
+        if aggregation_pipeline is None:
+            aggregation_pipeline = [{"$out": output_collection_name}]
+        else:
+            aggregation_pipeline.append({"$out": output_collection_name})
+
+        self.aggregate_data_and_generate_dataframe(
+                collection_name=input_collection_name,
+                aggregation_pipeline=aggregation_pipeline)
 
     def aggregate_data_and_generate_dataframe(self, collection_name: str, aggregation_pipeline: list, index: str = None, return_as_dataframe=True):
 
@@ -549,14 +555,14 @@ class MongodbHandler:
         data = self._database[collection_name].distinct(key)
 
         return data
-    
+
     def get_number_of_entries_in_collection(self, collection_name: str):
-        
+
         assert(isinstance(collection_name, str)),\
             "Parameter 'collection_name' must be a string type"
-        
+
         data = self._database[collection_name].count()
-        
+
         return data