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(connection, client:) ⇒ Mongo::Operation::Delete::BulkResult, ...

Execute the bulk write operation.

Examples:

operation.bulk_execute(connection, client: nil)

Parameters:

  • connection (Mongo::Server::Connection)

    The connection over which to send the operation.

  • 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



70
71
72
73
74
75
76
77
78
# File 'lib/mongo/operation/shared/write.rb', line 70

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

  if connection.features.op_msg_enabled?
    self.class::OpMsg.new(spec).execute(connection, client: client).bulk_result
  else
    self.class::Command.new(spec).execute(connection, 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
50
51
52
# File 'lib/mongo/operation/shared/write.rb', line 38

def execute(server, client:)
  server.with_connection do |connection|
    validate!(connection)
    op = if connection.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(connection, client: client)
    validate_result(result, client, connection)
  end
end