批量更新 Args: coll_name: 集合名 data: 单条数据 {"xxx":"xxx"} condition: 更新条件 {"_id": "xxxx"} upsert: 数据不存在则插入,默认为 False Returns: True / False
(self, coll_name, data: Dict, condition: Dict, upsert: bool = False)
| 335 | return True |
| 336 | |
| 337 | def update_many(self, coll_name, data: Dict, condition: Dict, upsert: bool = False): |
| 338 | """ |
| 339 | 批量更新 |
| 340 | Args: |
| 341 | coll_name: 集合名 |
| 342 | data: 单条数据 {"xxx":"xxx"} |
| 343 | condition: 更新条件 {"_id": "xxxx"} |
| 344 | upsert: 数据不存在则插入,默认为 False |
| 345 | |
| 346 | Returns: True / False |
| 347 | """ |
| 348 | try: |
| 349 | collection = self.get_collection(coll_name) |
| 350 | collection.update_many(condition, {"$set": data}, upsert=upsert) |
| 351 | except Exception as e: |
| 352 | log.error( |
| 353 | """ |
| 354 | error:{} |
| 355 | condition: {} |
| 356 | """.format( |
| 357 | e, condition |
| 358 | ) |
| 359 | ) |
| 360 | return False |
| 361 | else: |
| 362 | return True |
| 363 | |
| 364 | def update_batch( |
| 365 | self, |
no test coverage detected