An object wrapper for collection-level bulk write API results.
| 258 | |
| 259 | |
| 260 | class BulkWriteResult(_BulkWriteResultBase): |
| 261 | """An object wrapper for collection-level bulk write API results.""" |
| 262 | |
| 263 | __slots__ = () |
| 264 | |
| 265 | def __init__(self, bulk_api_result: dict[str, Any], acknowledged: bool) -> None: |
| 266 | """Create a BulkWriteResult instance. |
| 267 | |
| 268 | :param bulk_api_result: A result dict from the collection-level bulk write API |
| 269 | :param acknowledged: Was this write result acknowledged? If ``False`` |
| 270 | then all properties of this object will raise |
| 271 | :exc:`~pymongo.errors.InvalidOperation`. |
| 272 | """ |
| 273 | super().__init__(bulk_api_result, acknowledged) |
| 274 | |
| 275 | def __repr__(self) -> str: |
| 276 | return ( |
| 277 | f"{self.__class__.__name__}({self.bulk_api_result!r}, acknowledged={self.acknowledged})" |
| 278 | ) |
| 279 | |
| 280 | @property |
| 281 | def upserted_ids(self) -> Optional[dict[int, Any]]: |
| 282 | """A map of operation index to the _id of the upserted document.""" |
| 283 | self._raise_if_unacknowledged("upserted_ids") |
| 284 | if self.bulk_api_result: |
| 285 | return {upsert["index"]: upsert["_id"] for upsert in self.bulk_api_result["upserted"]} |
| 286 | return None |
| 287 | |
| 288 | |
| 289 | class ClientBulkWriteResult(_BulkWriteResultBase): |
no outgoing calls