浏览代码

add functin get_distinct_values_from_key to MongoHandler

tsteuer 4 年之前
父节点
当前提交
650ba4f52b
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      cdplib/db_handlers/MongodbHandler.py

+ 12 - 0
cdplib/db_handlers/MongodbHandler.py

@@ -521,6 +521,18 @@ class MongodbHandler:
             return [value[query_label] for value in data]
         else:
             return []
+        
+    def get_distinct_value_of_key(self, collection_name: str, key: str):
+        
+        assert(isinstance(collection_name, str)),\
+            "Parameter 'collection_name' must be a string type"
+        
+        assert(isinstance(key, str)),\
+            "Parameter 'key' must be a string type"
+        
+        data = self._database[collection_name].distinct(key)
+        
+        return data
 
 
 if __name__ == "__main__":