Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef1cf00

Browse filesBrowse files
author
changxiaofeng
committed
修复mongodb批量更新时,相同多条数据只更新一条的问题.
1 parent 8ea8f9f commit ef1cf00
Copy full SHA for ef1cf00

1 file changed

+31-31Lines changed: 31 additions & 31 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎feapder/db/mongodb.py‎

Copy file name to clipboardExpand all lines: feapder/db/mongodb.py
+31-31Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from urllib import parse
1313

1414
import pymongo
15-
from pymongo import MongoClient, UpdateOne
15+
from pymongo import MongoClient, UpdateOne, UpdateMany
1616
from pymongo.collection import Collection
1717
from pymongo.database import Database
1818
from pymongo.errors import DuplicateKeyError, BulkWriteError
@@ -23,14 +23,14 @@
2323

2424
class MongoDB:
2525
def __init__(
26-
self,
27-
ip=None,
28-
port=None,
29-
db=None,
30-
user_name=None,
31-
user_pass=None,
32-
url=None,
33-
**kwargs,
26+
self,
27+
ip=None,
28+
port=None,
29+
db=None,
30+
user_name=None,
31+
user_pass=None,
32+
url=None,
33+
**kwargs,
3434
):
3535
if not ip:
3636
ip = setting.MONGO_IP
@@ -97,7 +97,7 @@ def get_collection(self, coll_name, **kwargs) -> Collection:
9797
return self.db.get_collection(coll_name, **kwargs)
9898

9999
def find(
100-
self, coll_name: str, condition: Optional[Dict] = None, limit: int = 0, **kwargs
100+
self, coll_name: str, condition: Optional[Dict] = None, limit: int = 0, **kwargs
101101
) -> List[Dict]:
102102
"""
103103
@summary:
@@ -136,13 +136,13 @@ def find(
136136
return dataset
137137

138138
def add(
139-
self,
140-
coll_name,
141-
data: Dict,
142-
replace=False,
143-
update_columns=(),
144-
update_columns_value=(),
145-
insert_ignore=False,
139+
self,
140+
coll_name,
141+
data: Dict,
142+
replace=False,
143+
update_columns=(),
144+
update_columns_value=(),
145+
insert_ignore=False,
146146
):
147147
"""
148148
添加单条数据
@@ -198,13 +198,13 @@ def add(
198198
return affect_count
199199

200200
def add_batch(
201-
self,
202-
coll_name: str,
203-
datas: List[Dict],
204-
replace=False,
205-
update_columns=(),
206-
update_columns_value=(),
207-
condition_fields: dict = None,
201+
self,
202+
coll_name: str,
203+
datas: List[Dict],
204+
replace=False,
205+
update_columns=(),
206+
update_columns_value=(),
207+
condition_fields: dict = None,
208208
):
209209
"""
210210
批量添加数据
@@ -362,11 +362,11 @@ def update_many(self, coll_name, data: Dict, condition: Dict, upsert: bool = Fal
362362
return True
363363

364364
def update_batch(
365-
self,
366-
coll_name: str,
367-
update_data_list: List[Dict],
368-
condition_field: str,
369-
upsert: bool = False,
365+
self,
366+
coll_name: str,
367+
update_data_list: List[Dict],
368+
condition_field: str,
369+
upsert: bool = False,
370370
):
371371
"""
372372
批量更新数据
@@ -387,7 +387,7 @@ def update_batch(
387387

388388
for update_data in update_data_list:
389389
condition = {condition_field: update_data.get(condition_field)}
390-
update_operation = UpdateOne(
390+
update_operation = UpdateMany(
391391
condition, {"$set": update_data}, upsert=upsert
392392
)
393393
bulk_operations.append(update_operation)
@@ -468,7 +468,7 @@ def get_index_key(self, coll_name, index_name):
468468
return index_keys
469469

470470
def __get_update_condition(
471-
self, coll_name: str, data: dict, duplicate_errmsg: str
471+
self, coll_name: str, data: dict, duplicate_errmsg: str
472472
) -> dict:
473473
"""
474474
根据索引冲突的报错信息 获取更新条件

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.