Przeglądaj źródła

Add method that dissapeared in a merge

ogert 4 lat temu
rodzic
commit
f98767a54c
1 zmienionych plików z 14 dodań i 0 usunięć
  1. 14 0
      cdplib/db_handlers/MongodbHandler.py

+ 14 - 0
cdplib/db_handlers/MongodbHandler.py

@@ -516,6 +516,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__":