Explorar o código

Moved functionality from oebbmongohandler.

ogert %!s(int64=4) %!d(string=hai) anos
pai
achega
435f2c3224
Modificáronse 1 ficheiros con 18 adicións e 1 borrados
  1. 18 1
      cdplib/db_handlers/MongodbHandler.py

+ 18 - 1
cdplib/db_handlers/MongodbHandler.py

@@ -355,7 +355,10 @@ class MongodbHandler:
         if records:
             frames.append(pd.DataFrame(records))
 
-        return_df = pd.concat(frames, axis=0, sort=False)
+        if len(frames) > 1:
+            return_df = pd.concat(frames, axis=0, sort=False)
+        else:
+            return_df = frames[0]
 
         if index is not None:
             return_df.set_index(index, inplace=True)
@@ -503,6 +506,20 @@ class MongodbHandler:
         except Exception as error:
             self._log.log_and_raise_error(('There was a problem updating data for label: {}, Error: {}').format(update_label, error))
 
+    def which_document_in_list_exists(self, collection_name: str, query_label: str, query_values:list):
+        '''
+            Checking whether the document in the list exist or not.
+
+            :param str collection_name: collection to add data to
+            :param str query_label: label for the query
+            :param list query_values: values to see if they exist or not
+        '''
+        query = {query_label:{'$in': query_values}}
+        data = self._database[collection_name].find(query,{query_label:1, '_id':0})
+        if data.collection.count_documents(query) != 0:
+            return [value[query_label] for value in data]
+        else:
+            return []
 
 
 if __name__ == "__main__":