浏览代码

Add method that dissapeared in a merge

ogert 4 年之前
父节点
当前提交
f98767a54c
共有 1 个文件被更改,包括 14 次插入0 次删除
  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__":