123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Operation::Write Private

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/mongo/operation/shared/write.rb

Overview

Shared behavior of operations that write (update, insert, delete).

Since:

  • 2.5.2

Instance Method Summary

ResponseHandling - Included

#add_error_labels

Adds error labels to exceptions raised in the yielded to block, which should perform MongoDB operations and raise Mongo::Errors on failure.

#add_server_diagnostics

Yields to the block and, if the block raises an exception, adds a note to the exception with the address of the specified server.

#maybe_add_retryable_write_error_label!

A method that will add the RetryableWriteError label to an error if any of the following conditions are true:

#unpin_maybe

Unpins the session and/or the connection if the yielded to block raises errors that are required to unpin the session and the connection.

#validate_result

Instance Method Details

#bulk_execute(connection, context:) ⇒ Mongo::Operation::Delete::BulkResult, ...

Execute the bulk write operation.

Parameters:

Returns:

Since:

  • 2.5.2

[ GitHub ]

  
# File 'lib/mongo/operation/shared/write.rb', line 70

def bulk_execute(connection, context:)
  Lint.assert_type(connection, Server::Connection)

  if connection.features.op_msg_enabled?
    self.class::OpMsg.new(spec).execute(connection, context: context).bulk_result
  else
    self.class::Command.new(spec).execute(connection, context: context).bulk_result
  end
end

#execute(server, context:) ⇒ Mongo::Operation::Result

Execute the operation.

Parameters:

Returns:

Since:

  • 2.5.2

[ GitHub ]

  
# File 'lib/mongo/operation/shared/write.rb', line 37

def execute(server, context:)
  server.with_connection(connection_global_id: context.connection_global_id) do |connection|
    execute_with_connection(connection, context: context)
  end
end

#execute_with_connection(connection, context:) ⇒ Mongo::Operation::Result

Execute the operation.

Parameters:

Returns:

Since:

  • 2.5.2

[ GitHub ]

  
# File 'lib/mongo/operation/shared/write.rb', line 51

def execute_with_connection(connection, context:)
  validate!(connection)
  op = self.class::OpMsg.new(spec)

  result = op.execute(connection, context: context)
  validate_result(result, connection, context)
end

#validate!(connection) (private)

Since:

  • 2.5.2

[ GitHub ]

  
# File 'lib/mongo/operation/shared/write.rb', line 82

def validate!(connection)
  if !acknowledged_write?
    if collation
      raise Error::UnsupportedCollation.new(
          Error::UnsupportedCollation::UNACKNOWLEDGED_WRITES_MESSAGE)
    end
    if array_filters(connection)
      raise Error::UnsupportedArrayFilters.new(
          Error::UnsupportedArrayFilters::UNACKNOWLEDGED_WRITES_MESSAGE)
    end
  end
end