lib/mongo/operation/shared/write.rb in mongo-2.17.4 vs lib/mongo/operation/shared/write.rb in mongo-2.18.0.beta1

- old
+ new

@@ -33,22 +33,28 @@ # # @return [ Mongo::Operation::Result ] The operation result. # # @since 2.5.2 def execute(server, context:) - server.with_connection(service_id: context.service_id) 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, context: context) - validate_result(result, connection, context) + server.with_connection(connection_global_id: context.connection_global_id) do |connection| + execute_with_connection(connection, context: context) end + end + + # Execute the operation. + # + # @param [ Mongo::Server::Connection ] connection The connection to send + # the operation through. + # @param [ Operation::Context ] context The operation context. + # @param [ Hash ] options Operation execution options. + # + # @return [ Mongo::Operation::Result ] The operation result. + 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 # Execute the bulk write operation. # # @param [ Mongo::Server::Connection ] connection The connection over