Internal delete helper.
(
self,
conn: Connection,
criteria: Mapping[str, Any],
multi: bool,
write_concern: Optional[WriteConcern] = None,
op_id: Optional[int] = None,
ordered: bool = True,
collation: Optional[_CollationIn] = None,
hint: Optional[_IndexKeyHint] = None,
session: Optional[ClientSession] = None,
retryable_write: bool = False,
let: Optional[Mapping[str, Any]] = None,
comment: Optional[Any] = None,
)
| 1495 | ) |
| 1496 | |
| 1497 | def _delete( |
| 1498 | self, |
| 1499 | conn: Connection, |
| 1500 | criteria: Mapping[str, Any], |
| 1501 | multi: bool, |
| 1502 | write_concern: Optional[WriteConcern] = None, |
| 1503 | op_id: Optional[int] = None, |
| 1504 | ordered: bool = True, |
| 1505 | collation: Optional[_CollationIn] = None, |
| 1506 | hint: Optional[_IndexKeyHint] = None, |
| 1507 | session: Optional[ClientSession] = None, |
| 1508 | retryable_write: bool = False, |
| 1509 | let: Optional[Mapping[str, Any]] = None, |
| 1510 | comment: Optional[Any] = None, |
| 1511 | ) -> Mapping[str, Any]: |
| 1512 | """Internal delete helper.""" |
| 1513 | common.validate_is_mapping("filter", criteria) |
| 1514 | write_concern = write_concern or self.write_concern |
| 1515 | acknowledged = write_concern.acknowledged |
| 1516 | delete_doc = {"q": criteria, "limit": int(not multi)} |
| 1517 | collation = validate_collation_or_none(collation) |
| 1518 | if collation is not None: |
| 1519 | if not acknowledged: |
| 1520 | raise ConfigurationError("Collation is unsupported for unacknowledged writes.") |
| 1521 | else: |
| 1522 | delete_doc["collation"] = collation |
| 1523 | if hint is not None: |
| 1524 | if not acknowledged and conn.max_wire_version < 9: |
| 1525 | raise ConfigurationError( |
| 1526 | "Must be connected to MongoDB 4.4+ to use hint on unacknowledged delete commands." |
| 1527 | ) |
| 1528 | if not isinstance(hint, str): |
| 1529 | hint = helpers_shared._index_document(hint) |
| 1530 | delete_doc["hint"] = hint |
| 1531 | command = {"delete": self.name, "ordered": ordered, "deletes": [delete_doc]} |
| 1532 | |
| 1533 | if let is not None: |
| 1534 | common.validate_is_document_type("let", let) |
| 1535 | command["let"] = let |
| 1536 | |
| 1537 | if comment is not None: |
| 1538 | command["comment"] = comment |
| 1539 | |
| 1540 | # Delete command. |
| 1541 | result = conn.command( |
| 1542 | self._database.name, |
| 1543 | command, |
| 1544 | write_concern=write_concern, |
| 1545 | codec_options=self._write_response_codec_options, |
| 1546 | session=session, |
| 1547 | client=self._database.client, |
| 1548 | retryable_write=retryable_write, |
| 1549 | ) |
| 1550 | _check_write_command_response(result) |
| 1551 | return result |
| 1552 | |
| 1553 | def _delete_retryable( |
| 1554 | self, |
nothing calls this directly
no test coverage detected