Module: Mongo::Operation::Write

Includes:
ResponseHandling
Included in:
Delete, Insert, Update
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 collapse

Instance Method Details

#bulk_execute(server, client:) ⇒ Mongo::Operation::Delete::BulkResult, ...

Execute the bulk write operation.

Examples:

operation.bulk_execute(server, client: nil)

Parameters:

  • server (Mongo::Server)

    The server to send the operation to.

  • client (Mongo::Client)

    The client that will be used to perform auto-encryption if it is necessary to encrypt the command being executed (optional).

Returns:

Since:

  • 2.5.2



66
67
68
69
70
71
72
# File 'lib/mongo/operation/shared/write.rb', line 66

def bulk_execute(server, client:)
  if server.features.op_msg_enabled?
    self.class::OpMsg.new(spec).execute(server, client: client).bulk_result
  else
    self.class::Command.new(spec).execute(server, client: client).bulk_result
  end
end

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

Execute the operation.

Examples:

operation.execute(server, client: nil)

Parameters:

  • server (Mongo::Server)

    The server to send the operation to.

  • client (Mongo::Client)

    The client that will be used to perform auto-encryption if it is necessary to encrypt the command being executed (optional).

Returns:

Since:

  • 2.5.2



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mongo/operation/shared/write.rb', line 38

def execute(server, client:)
  validate!
  op = if server.features.op_msg_enabled?
      self.class::OpMsg.new(spec)
    elsif !acknowledged_write?
      self.class::Legacy.new(spec)
    else
      self.class::Command.new(spec)
    end
  result = op.execute(server, client: client)
  validate_result(result, server)
end