更新 Args: coll_name: 集合名 data: 单条数据 {"xxx":"xxx"} condition: 更新条件 {"_id": "xxxx"} upsert: 数据不存在则插入,默认为 False Returns: True / False
(self, coll_name, data: Dict, condition: Dict, upsert: bool = False)
| 308 | return result["n"] |
| 309 | |
| 310 | def update(self, coll_name, data: Dict, condition: Dict, upsert: bool = False): |
| 311 | """ |
| 312 | 更新 |
| 313 | Args: |
| 314 | coll_name: 集合名 |
| 315 | data: 单条数据 {"xxx":"xxx"} |
| 316 | condition: 更新条件 {"_id": "xxxx"} |
| 317 | upsert: 数据不存在则插入,默认为 False |
| 318 | |
| 319 | Returns: True / False |
| 320 | """ |
| 321 | try: |
| 322 | collection = self.get_collection(coll_name) |
| 323 | collection.update_one(condition, {"$set": data}, upsert=upsert) |
| 324 | except Exception as e: |
| 325 | log.error( |
| 326 | """ |
| 327 | error:{} |
| 328 | condition: {} |
| 329 | """.format( |
| 330 | e, condition |
| 331 | ) |
| 332 | ) |
| 333 | return False |
| 334 | else: |
| 335 | return True |
| 336 | |
| 337 | def update_many(self, coll_name, data: Dict, condition: Dict, upsert: bool = False): |
| 338 | """ |
no test coverage detected