(self, sock_info, generator, write_concern)
return full_result
Execute using write commands.
Execute using write commands.
Execute using write commands .
def execute_command(self, sock_info, generator, write_concern):
        """Execute using write commands.
        """
        # nModified is only reported for write commands, not legacy ops.
        full_result = {
            "writeErrors": [],
            "writeConcernErrors": [],
            "nInserted": 0,
            "nUpserted": 0,
            "nMatched": 0,
            "nModified": 0,
            "nRemoved": 0,
            "upserted": [],
        }
        op_id = _randint()
        db_name = self.collection.database.name
        listeners = self.collection.database.client._event_listeners

        for run in generator:
            cmd = SON([(_COMMANDS[run.op_type], self.collection.name),
                       ('ordered', self.ordered)])
            if write_concern.document:
                cmd['writeConcern'] = write_concern.document
            if self.bypass_doc_val and sock_info.max_wire_version >= 4:
                cmd['bypassDocumentValidation'] = True

            bwc = _BulkWriteContext(db_name, cmd, sock_info, op_id, listeners)
            results = _do_batched_write_command(
                self.namespace, run.op_type, cmd,
                run.ops, True, self.collection.codec_options, bwc)

            _merge_command(run, full_result, results)
            # We're supposed to continue if errors are
            # at the write concern level (e.g. wtimeout)
            if self.ordered and full_result['writeErrors']:
                break

        if full_result["writeErrors"] or full_result["writeConcernErrors"]:
            if full_result['writeErrors']:
                full_result['writeErrors'].sort(
                    key=lambda error: error['index'])
            raise BulkWriteError(full_result)
        return full_result
def execute_command ( self , sock_info , generator , write_concern ) : # nModified is only reported for write commands, not legacy ops. full_result = { "writeErrors" : [ ] , "writeConcernErrors" : [ ] , "nInserted" : 0 , "nUpserted" : 0 , "nMatched" : 0 , "nModified" : 0 , "nRemoved" : 0 , "upserted" : [ ] , } op_id = _randint ( ) db_name = self . collection . database . name listeners = self . collection . database . client . _event_listeners for run in generator : cmd = SON ( [ ( _COMMANDS [ run . op_type ] , self . collection . name ) , ( 'ordered' , self . ordered ) ] ) if write_concern . document : cmd [ 'writeConcern' ] = write_concern . document if self . bypass_doc_val and sock_info . max_wire_version >= 4 : cmd [ 'bypassDocumentValidation' ] = True bwc = _BulkWriteContext ( db_name , cmd , sock_info , op_id , listeners ) results = _do_batched_write_command ( self . namespace , run . op_type , cmd , run . ops , True , self . collection . codec_options , bwc ) _merge_command ( run , full_result , results ) # We're supposed to continue if errors are # at the write concern level (e.g. wtimeout) if self . ordered and full_result [ 'writeErrors' ] : break if full_result [ "writeErrors" ] or full_result [ "writeConcernErrors" ] : if full_result [ 'writeErrors' ] : full_result [ 'writeErrors' ] . sort ( key = lambda error : error [ 'index' ] ) raise BulkWriteError ( full_result ) return full_result