ソースを参照

Add possibility to supress the _id value in query_data_and_generate_dataframe

ogert 5 年 前
コミット
3644bc26a8
共有1 個のファイルを変更した3 個の追加3 個の削除を含む
  1. 3 3
      cdplib/db_handlers/MongodbHandler.py

+ 3 - 3
cdplib/db_handlers/MongodbHandler.py

@@ -247,15 +247,15 @@ class MongodbHandler:
 
 
     def query_data_and_generate_dataframe(self, collection_name: str, attribute: str = None,
     def query_data_and_generate_dataframe(self, collection_name: str, attribute: str = None,
                                           attribute_value: str = None, comparison_operator: str = '$eq',
                                           attribute_value: str = None, comparison_operator: str = '$eq',
-                                          index = None, return_as_dataframe: bool = True):
+                                          index = None, return_as_dataframe: bool = True, return_id: bool = False):
         '''
         '''
 
 
         '''
         '''
         try:
         try:
             if attribute == None or attribute_value == None:
             if attribute == None or attribute_value == None:
-                data = self._database[collection_name].find()
+                data = self._database[collection_name].find({'_id': return_id})
             else:
             else:
-                data = self._database[collection_name].find({attribute: {comparison_operator: attribute_value}})
+                data = self._database[collection_name].find({attribute: {comparison_operator: attribute_value}, {'_id': return_id}})
 
 
         except Exception as error:
         except Exception as error:
             self._log.log_and_raise_error(('An error occured trying to query data from {}, with query {}: {}:{}. \nError:{}').format(collection_name, attribute, comparison_operator, attribute_value, error))
             self._log.log_and_raise_error(('An error occured trying to query data from {}, with query {}: {}:{}. \nError:{}').format(collection_name, attribute, comparison_operator, attribute_value, error))