From b74a000e5eb7c5c3c5fa88f34d0ba174dde7b93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Mon, 29 Aug 2022 13:45:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=95=B0=E7=BB=84=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E6=9D=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DBHelper/MongoHelper.py | 13 +++++++++++++ DBHelper/test.py | 37 ++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/DBHelper/MongoHelper.py b/DBHelper/MongoHelper.py index 33c661b..fe8739e 100644 --- a/DBHelper/MongoHelper.py +++ b/DBHelper/MongoHelper.py @@ -258,6 +258,19 @@ class MongoHelper: collection.delete_one(param3) return True + def delete_single_data_in_array(self, param1, param2, param3, param4): + """ + 删除数组中的单条数据 + param1: str 数据库 + param2: str 数据表 + param3: dict 一级字段查询条件 + param4: dict 二级字段查询条件 + return: None + """ + collection = self.client[param1][param2] + collection.update_one(param3, {"$pull": param4}) + return True + def find_file(self, param1, param2, param3): """ 读取一个文件 diff --git a/DBHelper/test.py b/DBHelper/test.py index ee747e0..0c08c85 100644 --- a/DBHelper/test.py +++ b/DBHelper/test.py @@ -1,17 +1,24 @@ from DBHelper.MongoHelperInstance import DB_TEST -DB_TEST.update_single_data_in_array( - "WR_DataBase_v2_test", - "C3.2_股东信息", - {"企业ID": "xzTtCERe"}, - {"股东列表": {"股东名称": "A股股东"}}, - { - "股东ID": 2390620707, - "股东名称": "A股股东", - "股东类型": "其他", - "股东性质": None, - "持股比例": "62.28%", - "认缴出资额": "181314.2855万人民币", - "认缴出资日期": "2016-09-30" - } -) +# DB_TEST.update_single_data_in_array( +# "WR_DataBase_v2_test", +# "C3.2_股东信息", +# {"企业ID": "xzTtCERe"}, +# {"股东列表": {"股东名称": "A股股东"}}, +# { +# "股东ID": 2390620707, +# "股东名称": "A股股东", +# "股东类型": "其他", +# "股东性质": None, +# "持股比例": "62.28%", +# "认缴出资额": "181314.2855万人民币", +# "认缴出资日期": "2016-09-30" +# } +# ) + +# DB_TEST.delete_single_data_in_array( +# "WR_DataBase_v2_test", +# "C3.2_股东信息", +# {"企业ID": "xzTtCERe"}, +# {"股东列表": {"股东名称": "A股股东"}} +# )