MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / execute

Method execute

pymongo/synchronous/client_bulk.py:736–763  ·  view source on GitHub ↗

Execute operations.

(
        self,
        session: Optional[ClientSession],
        operation: str,
    )

Source from the content-addressed store, hash-verified

734 return self.execute_command_unack(conn)
735
736 def execute(
737 self,
738 session: Optional[ClientSession],
739 operation: str,
740 ) -> Any:
741 """Execute operations."""
742 if not self.ops:
743 raise InvalidOperation("No operations to execute")
744 if self.executed:
745 raise InvalidOperation("Bulk operations can only be executed once.")
746 self.executed = True
747 session = _validate_session_write_concern(session, self.write_concern)
748
749 if not self.write_concern.acknowledged:
750 with self.client._conn_for_writes(session, operation) as connection:
751 if connection.max_wire_version < 25:
752 raise InvalidOperation(
753 "MongoClient.bulk_write requires MongoDB server version 8.0+."
754 )
755 self.execute_no_results(connection)
756 return ClientBulkWriteResult(None, False, False) # type: ignore[arg-type]
757
758 result = self.execute_command(session, operation)
759 return ClientBulkWriteResult(
760 result,
761 self.write_concern.acknowledged,
762 self.verbose_results,
763 )

Callers

nothing calls this directly

Calls 6

execute_no_resultsMethod · 0.95
execute_commandMethod · 0.95
InvalidOperationClass · 0.90
_conn_for_writesMethod · 0.45

Tested by

no test coverage detected