From 044eaeaaf3fa3c5e996077992748b927a8769f69 Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 11:53:41 +0200 Subject: [PATCH 1/6] RUBY-3085 Remove pre-OP_MSG wire protocols --- lib/mongo/protocol.rb | 3 - lib/mongo/protocol/delete.rb | 172 ----------------------- lib/mongo/protocol/insert.rb | 181 ------------------------ lib/mongo/protocol/update.rb | 214 ----------------------------- spec/mongo/protocol/delete_spec.rb | 185 ------------------------- spec/mongo/protocol/insert_spec.rb | 179 ------------------------ spec/mongo/protocol/update_spec.rb | 204 --------------------------- 7 files changed, 1138 deletions(-) delete mode 100644 lib/mongo/protocol/delete.rb delete mode 100644 lib/mongo/protocol/insert.rb delete mode 100644 lib/mongo/protocol/update.rb delete mode 100644 spec/mongo/protocol/delete_spec.rb delete mode 100644 spec/mongo/protocol/insert_spec.rb delete mode 100644 spec/mongo/protocol/update_spec.rb diff --git a/lib/mongo/protocol.rb b/lib/mongo/protocol.rb index b09097f3cd..4289a38835 100644 --- a/lib/mongo/protocol.rb +++ b/lib/mongo/protocol.rb @@ -10,12 +10,9 @@ # Client Requests require 'mongo/protocol/compressed' -require 'mongo/protocol/delete' require 'mongo/protocol/get_more' -require 'mongo/protocol/insert' require 'mongo/protocol/kill_cursors' require 'mongo/protocol/query' -require 'mongo/protocol/update' require 'mongo/protocol/msg' # Server Responses diff --git a/lib/mongo/protocol/delete.rb b/lib/mongo/protocol/delete.rb deleted file mode 100644 index 67478395cb..0000000000 --- a/lib/mongo/protocol/delete.rb +++ /dev/null @@ -1,172 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2014-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Protocol - - # MongoDB Wire protocol Delete message. - # - # This is a client request message that is sent to the server in order - # to delete selected documents in the specified namespace. - # - # The operation, by default, operates on many documents. Setting - # the +:single_remove+ flag allows for a single matching document - # to be removed. - # - # @api semipublic - class Delete < Message - - # Creates a new Delete message - # - # @example Remove all users named Tyler. - # Query.new('xgen', 'users', {:name => 'Tyler'}) - # - # @param database [String, Symbol] The database to remove from. - # @param collection [String, Symbol] The collection to remove from. - # @param selector [Hash] The query used to select doc(s) to remove. - # @param options [Hash] The additional delete options. - # - # @option options :flags [Array] The flags for the delete message. - # - # Supported flags: +:single_remove+ - def initialize(database, collection, selector, options = {}) - @database = database - @namespace = "#{database}.#{collection}" - @selector = selector - @flags = options[:flags] || [] - @upconverter = Upconverter.new(collection, selector, options) - super - end - - # Return the event payload for monitoring. - # - # @example Return the event payload. - # message.payload - # - # @return [ BSON::Document ] The event payload. - # - # @since 2.1.0 - def payload - BSON::Document.new( - command_name: 'delete', - database_name: @database, - command: upconverter.command, - request_id: request_id - ) - end - - protected - - attr_reader :upconverter - - private - - # The operation code required to specify a Delete message. - # @return [Fixnum] the operation code. - # - # @since 2.5.0 - OP_CODE = 2006 - - # Available flags for a Delete message. - FLAGS = [:single_remove] - - # Field representing Zero encoded as an Int32. - field :zero, Zero - - # @!attribute - # @return [String] The namespace for this Delete message. - field :namespace, CString - - # @!attribute - # @return [Array] The flags for this Delete message. - field :flags, BitVector.new(FLAGS) - - # @!attribute - # @return [Hash] The selector for this Delete message. - field :selector, Document - - # Converts legacy delete messages to the appropriare OP_COMMAND style - # message. - # - # @since 2.1.0 - class Upconverter - - # The delete command constant. - # - # @since 2.2.0 - DELETE = 'delete'.freeze - - # The deletes command constant. - # - # @since 2.2.0 - DELETES = 'deletes'.freeze - - # @return [ String ] collection The name of the collection. - attr_reader :collection - - # @return [ BSON::Document, Hash ] filter The query filter or command. - attr_reader :filter - - # @return [ Hash ] options The options. - attr_reader :options - - # Instantiate the upconverter. - # - # @example Instantiate the upconverter. - # Upconverter.new('users', { name: 'test' }) - # - # @param [ String ] collection The name of the collection. - # @param [ BSON::Document, Hash ] filter The filter or command. - # - # @since 2.1.0 - def initialize(collection, filter, options) - @collection = collection - @filter = filter - @options = options - end - - # Get the upconverted command. - # - # @example Get the command. - # upconverter.command - # - # @return [ BSON::Document ] The upconverted command. - # - # @since 2.1.0 - def command - document = BSON::Document.new - document.store(DELETE, collection) - document.store(DELETES, [ BSON::Document.new(Message::Q => filter, Message::LIMIT => limit) ]) - document.store(Message::ORDERED, true) - document - end - - private - - def limit - if options.key?(:flags) - options[:flags].include?(:single_remove) ? 1 : 0 - else - 0 - end - end - end - - Registry.register(OP_CODE, self) - end - end -end diff --git a/lib/mongo/protocol/insert.rb b/lib/mongo/protocol/insert.rb deleted file mode 100644 index 6b02daf84b..0000000000 --- a/lib/mongo/protocol/insert.rb +++ /dev/null @@ -1,181 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2014-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Protocol - - # MongoDB Wire protocol Insert message. - # - # This is a client request message that is sent to the server in order - # to insert documents within a namespace. - # - # The operation only has one flag +:continue_on_error+ which the user - # can use to instruct the database server to continue processing a bulk - # insertion if one happens to fail (e.g. due to duplicate IDs). This makes - # builk insert behave similarly to a seires of single inserts, except - # lastError will be set if any insert fails, not just the last one. - # - # If multiple errors occur, only the most recent will be reported by the - # getLastError mechanism. - # - # @api semipublic - class Insert < Message - - # Creates a new Insert message - # - # @example Insert a user document - # Insert.new('xgen', 'users', [{:name => 'Tyler'}]) - # - # @example Insert serveral user documents and continue on errors - # Insert.new('xgen', 'users', users, :flags => [:continue_on_error]) - # - # @param database [String, Symbol] The database to insert into. - # @param collection [String, Symbol] The collection to insert into. - # @param documents [Array] The documents to insert. - # @param options [Hash] Additional options for the insertion. - # - # @option options :flags [Array] The flags for the insertion message. - # Supported flags: +:continue_on_error+ - # @option options [ true, false ] validating_keys Whether keys should be - # validated for being valid document keys (i.e. not begin with $ and - # not contain dots). - def initialize(database, collection, documents, options = {}) - @database = database - @namespace = "#{database}.#{collection}" - @documents = documents - @flags = options[:flags] || [] - @upconverter = Upconverter.new(collection, documents, options) - @options = options - super - end - - # Return the event payload for monitoring. - # - # @example Return the event payload. - # message.payload - # - # @return [ BSON::Document ] The event payload. - # - # @since 2.1.0 - def payload - BSON::Document.new( - command_name: 'insert', - database_name: @database, - command: upconverter.command, - request_id: request_id - ) - end - - protected - - attr_reader :upconverter - - private - - def validating_keys? - @options.fetch(:validating_keys, true) - end - - # The operation code required to specify an Insert message. - # @return [Fixnum] the operation code. - # - # @since 2.5.0 - OP_CODE = 2002 - - # Available flags for an Insert message. - FLAGS = [:continue_on_error] - - # @!attribute - # @return [Array] The flags for this Insert message. - field :flags, BitVector.new(FLAGS) - - # @!attribute - # @return [String] The namespace for this Insert message. - field :namespace, CString - - # @!attribute - # @return [Array] The documents to insert. - field :documents, Document, true - - # Converts legacy insert messages to the appropriare OP_COMMAND style - # message. - # - # @since 2.1.0 - class Upconverter - - # Insert field constant. - # - # @since 2.1.0 - INSERT = 'insert'.freeze - - # Documents field constant. - # - # @since 2.1.0 - DOCUMENTS = 'documents'.freeze - - # Write concern field constant. - # - # @since 2.1.0 - WRITE_CONCERN = 'writeConcern'.freeze - - # @return [ String ] collection The name of the collection. - attr_reader :collection - - # @return [ Array ] documents The documents to insert. - attr_reader :documents - - # @return [ Hash ] options The options. - attr_reader :options - - # Instantiate the upconverter. - # - # @example Instantiate the upconverter. - # Upconverter.new('users', documents) - # - # @param [ String ] collection The name of the collection. - # @param [ Array ] documents The documents. - # @param [ Hash ] options The options. - # - # @since 2.1.0 - def initialize(collection, documents, options) - @collection = collection - @documents = documents - @options = options - end - - # Get the upconverted command. - # - # @example Get the command. - # upconverter.command - # - # @return [ BSON::Document ] The upconverted command. - # - # @since 2.1.0 - def command - document = BSON::Document.new - document.store(INSERT, collection) - document.store(DOCUMENTS, documents) - document.store(Message::ORDERED, options.fetch(:ordered, true)) - document.merge!(WRITE_CONCERN => options[:write_concern].options) if options[:write_concern] - document - end - end - - Registry.register(OP_CODE, self) - end - end -end diff --git a/lib/mongo/protocol/update.rb b/lib/mongo/protocol/update.rb deleted file mode 100644 index f74c0208af..0000000000 --- a/lib/mongo/protocol/update.rb +++ /dev/null @@ -1,214 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2014-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Protocol - - # MongoDB Wire protocol Update message. - # - # This is a client request message that is sent to the server in order - # to update documents matching the provided query. - # - # The default is to update a single document. In order to update many at - # a time users should set the +:multi_update+ flag for the update. - # - # If an upsert (update or insert) is desired, users can set the +:upsert+ - # flag in order to indicate they would like to insert the merged selector - # and update if no document matching the update query currently exists. - # - # @api semipublic - class Update < Message - - # Creates a new Update message - # - # @example Update single document - # Update.new('xgen', 'users', {:name => 'Tyler'}, {:name => 'Bob'}) - # - # @example Perform a multi update - # Update.new('xgen', 'users', - # {:age => 20}, {:age => 21}, :flags => [:multi_update]) - # - # @example Perform an upsert - # Update.new('xgen', 'users', {:name => 'Tyler'}, :flags => [:upsert]) - # - # @param database [String, Symbol] The database to update. - # @param collection [String, Symbol] The collection to update. - # @param selector [Hash] The update selector. - # @param update [Hash] The update to perform. - # @param options [Hash] The additional query options. - # - # @option options :flags [Array] The flags for the update message. - # - # Supported flags: +:upsert+, +:multi_update+ - def initialize(database, collection, selector, update, options = {}) - @database = database - @collection = collection - @namespace = "#{database}.#{collection}" - @selector = selector - @update = update - @flags = options[:flags] || [] - @upconverter = Upconverter.new(collection, selector, update, flags) - super - end - - # Return the event payload for monitoring. - # - # @example Return the event payload. - # message.payload - # - # @return [ BSON::Document ] The event payload. - # - # @since 2.1.0 - def payload - BSON::Document.new( - command_name: 'update', - database_name: @database, - command: upconverter.command, - request_id: request_id - ) - end - - protected - - attr_reader :upconverter - - private - - # The operation code required to specify an Update message. - # @return [Fixnum] the operation code. - # - # @since 2.5.0 - OP_CODE = 2001 - - # Available flags for an Update message. - FLAGS = [:upsert, :multi_update] - - # Field representing Zero encoded as an Int32. - field :zero, Zero - - # @!attribute - # @return [String] The namespace for this Update message. - field :namespace, CString - - # @!attribute - # @return [Array] The flags for this Update message. - field :flags, BitVector.new(FLAGS) - - # @!attribute - # @return [Hash] The selector for this Update message. - field :selector, Document - - # @!attribute - # @return [Hash] The update for this Delete message. - field :update, Document - - # Converts legacy update messages to the appropriare OP_COMMAND style - # message. - # - # @since 2.1.0 - class Upconverter - - # The multi constant. - # - # @since 2.2.0 - MULTI = 'multi'.freeze - - # The u constant. - # - # @since 2.2.0 - U = 'u'.freeze - - # The update constant. - # - # @since 2.2.0 - UPDATE = 'update'.freeze - - # The updates constant. - # - # @since 2.2.0 - UPDATES = 'updates'.freeze - - # The upsert constant. - # - # @since 2.2.0 - UPSERT = 'upsert'.freeze - - # @return [ String ] collection The name of the collection. - attr_reader :collection - - # @return [ Hash ] filter The filter. - attr_reader :filter - - # @return [ Hash ] update The update. - attr_reader :update - - # @return [ Array ] flags The flags. - attr_reader :flags - - # Instantiate the upconverter. - # - # @example Instantiate the upconverter. - # Upconverter.new( - # 'users', - # { name: 'test' }, - # { '$set' => { 'name' => 't' }}, - # [] - # ) - # - # @param [ String ] collection The name of the collection. - # @param [ Hash ] filter The filter. - # @param [ Hash ] update The update. - # @param [ Array ] flags The flags. - # - # @since 2.1.0 - def initialize(collection, filter, update, flags) - @collection = collection - @filter = filter - @update = update - @flags = flags - end - - # Get the upconverted command. - # - # @example Get the command. - # upconverter.command - # - # @return [ BSON::Document ] The upconverted command. - # - # @since 2.1.0 - def command - document = BSON::Document.new - updates = BSON::Document.new - updates.store(Message::Q, filter) - updates.store(U, update) - if flags.include?(:multi_update) - updates.store(MULTI, true) - end - if flags.include?(:upsert) - updates.store(UPSERT, true) - end - document.store(UPDATE, collection) - document.store(Message::ORDERED, true) - document.store(UPDATES, [ updates ]) - document - end - end - - Registry.register(OP_CODE, self) - end - end -end diff --git a/spec/mongo/protocol/delete_spec.rb b/spec/mongo/protocol/delete_spec.rb deleted file mode 100644 index d3bb0566c6..0000000000 --- a/spec/mongo/protocol/delete_spec.rb +++ /dev/null @@ -1,185 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'lite_spec_helper' -require 'support/shared/protocol' - -describe Mongo::Protocol::Delete do - - let(:opcode) { 2006 } - let(:db) { SpecConfig.instance.test_db } - let(:collection_name) { 'protocol-test' } - let(:ns) { "#{db}.#{collection_name}" } - let(:selector) { { :name => 'Tyler' } } - let(:options) { Hash.new } - - let(:message) do - described_class.new(db, collection_name, selector, options) - end - - describe '#initialize' do - - it 'sets the namepsace' do - expect(message.namespace).to eq(ns) - end - - it 'sets the selector' do - expect(message.selector).to eq(selector) - end - - context 'when options are provided' do - - context 'when flags are provided' do - let(:options) { { :flags => [:single_remove] } } - - it 'sets the flags' do - expect(message.flags).to eq(options[:flags]) - end - end - end - end - - describe '#==' do - - context 'when the other is a delete' do - - context 'when the fields are equal' do - let(:other) do - described_class.new(db, collection_name, selector, options) - end - - it 'returns true' do - expect(message).to eq(other) - end - end - - context 'when the database is not equal' do - let(:other) do - described_class.new('tyler', collection_name, selector, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the collection is not equal' do - let(:other) do - described_class.new(db, 'tyler', selector, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the selector is not equal' do - let(:other) do - described_class.new(db, collection_name, { :a => 1 }, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the options are not equal' do - let(:other) do - described_class.new(db, collection_name, selector, :flags => [:single_remove]) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - end - - context 'when the other is not a delete' do - let(:other) do - expect(message).not_to eq('test') - end - end - end - - describe '#hash' do - let(:values) do - message.send(:fields).map do |field| - message.instance_variable_get(field[:name]) - end - end - - it 'returns a hash of the field values' do - expect(message.hash).to eq(values.hash) - end - end - - describe '#replyable?' do - - it 'returns false' do - expect(message).to_not be_replyable - end - end - - describe '#serialize' do - let(:bytes) { message.serialize } - - include_examples 'message with a header' - - describe 'zero' do - let(:field) { bytes.to_s[16..19] } - - it 'serializes a zero' do - expect(field).to be_int32(0) - end - end - - describe 'namespace' do - let(:field) { bytes.to_s[20..36] } - it 'serializes the namespace' do - expect(field).to be_cstring(ns) - end - end - - describe 'flags' do - let(:field) { bytes.to_s[37..40] } - - context 'when no flags are provided' do - it 'does not set any bits' do - expect(field).to be_int32(0) - end - end - - context 'when flags are provided' do - let(:options) { { :flags => flags } } - - context 'single remove flag' do - let(:flags) { [:single_remove] } - it 'sets the first bit' do - expect(field).to be_int32(1) - end - end - end - end - - describe 'selector' do - let(:field) { bytes.to_s[41..-1] } - it 'serializes the selector' do - expect(field).to be_bson(selector) - end - end - end - - describe '#registry' do - - context 'when the class is loaded' do - - it 'registers the op code in the Protocol Registry' do - expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class) - end - - it 'creates an #op_code instance method' do - expect(message.op_code).to eq(described_class::OP_CODE) - end - end - end -end diff --git a/spec/mongo/protocol/insert_spec.rb b/spec/mongo/protocol/insert_spec.rb deleted file mode 100644 index 804963a17a..0000000000 --- a/spec/mongo/protocol/insert_spec.rb +++ /dev/null @@ -1,179 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'lite_spec_helper' -require 'support/shared/protocol' - -describe Mongo::Protocol::Insert do - - let(:opcode) { 2002 } - let(:db) { SpecConfig.instance.test_db } - let(:collection_name) { 'protocol-test' } - let(:ns) { "#{db}.#{collection_name}" } - let(:doc1) { { :name => 'Tyler' } } - let(:doc2) { { :name => 'Brandon' } } - let(:docs) { [doc1, doc2] } - let(:options) { Hash.new } - - let(:message) do - described_class.new(db, collection_name, docs, options) - end - - describe '#initialize' do - - it 'sets the namepsace' do - expect(message.namespace).to eq(ns) - end - - it 'sets the documents' do - expect(message.documents).to eq(docs) - end - - context 'when options are provided' do - - context 'when flags are provided' do - let(:options) { { :flags => [:continue_on_error] } } - - it 'sets the flags' do - expect(message.flags).to eq(options[:flags]) - end - end - end - end - - describe '#==' do - - context 'when the other is an insert' do - - context 'when the fields are equal' do - let(:other) do - described_class.new(db, collection_name, docs, options) - end - - it 'returns true' do - expect(message).to eq(other) - end - end - - context 'when the database is not equal' do - let(:other) do - described_class.new('tyler', collection_name, docs, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the collection is not equal' do - let(:other) do - described_class.new(db, 'tyler', docs, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the documents are not equal' do - let(:other) do - described_class.new(db, collection_name, docs[1..1], options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the options are not equal' do - let(:other) do - described_class.new(db, collection_name, docs, :flags => [:continue_on_error]) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - end - - context 'when the other is not an insert' do - let(:other) do - expect(message).not_to eq('test') - end - end - end - - describe '#hash' do - let(:values) do - message.send(:fields).map do |field| - message.instance_variable_get(field[:name]) - end - end - - it 'returns a hash of the field values' do - expect(message.hash).to eq(values.hash) - end - end - - describe '#replyable?' do - - it 'returns false' do - expect(message).to_not be_replyable - end - end - - describe '#serialize' do - let(:bytes) { message.serialize } - - include_examples 'message with a header' - - describe 'flags' do - let(:field) { bytes.to_s[16..19] } - - context 'when no flags are provided' do - it 'does not set any bits' do - expect(field).to be_int32(0) - end - end - - context 'when flags are provided' do - let(:options) { { :flags => flags } } - - context 'continue on error flag' do - let(:flags) { [:continue_on_error] } - it 'sets the first bit' do - expect(field).to be_int32(1) - end - end - end - end - - describe 'namespace' do - let(:field) { bytes.to_s[20..36] } - it 'serializes the namespace' do - expect(field).to be_cstring(ns) - end - end - - describe 'documents' do - let(:field) { bytes.to_s[37..-1] } - it 'serializes the documents' do - expect(field).to be_bson_sequence(docs) - end - end - end - - describe '#registry' do - - context 'when the class is loaded' do - - it 'registers the op code in the Protocol Registry' do - expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class) - end - - it 'creates an #op_code instance method' do - expect(message.op_code).to eq(described_class::OP_CODE) - end - end - end -end diff --git a/spec/mongo/protocol/update_spec.rb b/spec/mongo/protocol/update_spec.rb deleted file mode 100644 index 98412f1db8..0000000000 --- a/spec/mongo/protocol/update_spec.rb +++ /dev/null @@ -1,204 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'lite_spec_helper' -require 'support/shared/protocol' - -describe Mongo::Protocol::Update do - - let(:opcode) { 2001 } - let(:db) { SpecConfig.instance.test_db } - let(:collection_name) { 'protocol-test' } - let(:ns) { "#{db}.#{collection_name}" } - let(:selector) { { :name => 'Tyler' } } - let(:update_doc) { { :name => 'Bob' } } - let(:options) { Hash.new } - - let(:message) do - described_class.new(db, collection_name, selector, update_doc, options) - end - - describe '#initialize' do - - it 'sets the namespace' do - expect(message.namespace).to eq(ns) - end - - it 'sets the selector' do - expect(message.selector).to eq(selector) - end - - it 'sets the update document' do - expect(message.update).to eq(update_doc) - end - end - - describe '#==' do - - context 'when the other is an update' do - - context 'when the fields are equal' do - let(:other) do - described_class.new(db, collection_name, selector, update_doc, options) - end - - it 'returns true' do - expect(message).to eq(other) - end - end - - context 'when the database is not equal' do - let(:other) do - described_class.new('tyler', collection_name, selector, update_doc, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the collection is not equal' do - let(:other) do - described_class.new(db, 'tyler', selector, update_doc, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the selector is not equal' do - let(:other) do - described_class.new(db, collection_name, { :a => 1 }, update_doc, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the update document is not equal' do - let(:other) do - described_class.new(db, collection_name, selector, { :a => 1 }, options) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - - context 'when the options are not equal' do - let(:other) do - described_class.new(db, collection_name, selector, update_doc, - :flags => :upsert) - end - - it 'returns false' do - expect(message).not_to eq(other) - end - end - end - - context 'when the other is not a query' do - let(:other) do - expect(message).not_to eq('test') - end - end - end - - describe '#hash' do - let(:values) do - message.send(:fields).map do |field| - message.instance_variable_get(field[:name]) - end - end - - it 'returns a hash of the field values' do - expect(message.hash).to eq(values.hash) - end - end - - describe '#replyable?' do - - it 'returns false' do - expect(message).to_not be_replyable - end - end - - describe '#serialize' do - let(:bytes) { message.serialize } - - include_examples 'message with a header' - - describe 'zero' do - let(:field) { bytes.to_s[16..19] } - - it 'serializes a zero' do - expect(field).to be_int32(0) - end - end - - describe 'namespace' do - let(:field) { bytes.to_s[20..36] } - it 'serializes the namespace' do - expect(field).to be_cstring(ns) - end - end - - describe 'flags' do - let(:field) { bytes.to_s[37..40] } - - context 'when no flags are provided' do - it 'does not set any bits' do - expect(field).to be_int32(0) - end - end - - context 'when flags are provided' do - let(:options) { { :flags => flags } } - - context 'upsert flag' do - let(:flags) { [:upsert] } - it 'sets the first bit' do - expect(field).to be_int32(1) - end - end - - context 'multi update' do - let(:flags) { [:multi_update] } - it 'sets the second bit' do - expect(field).to be_int32(2) - end - end - end - end - - describe 'selector' do - let(:field) { bytes.to_s[41..61] } - it 'serializes the selector' do - expect(field).to be_bson(selector) - end - end - - describe 'update' do - let(:field) { bytes.to_s[62..80] } - it 'serializes the update' do - expect(field).to be_bson(update_doc) - end - end - end - - describe '#registry' do - - context 'when the class is loaded' do - - it 'registers the op code in the Protocol Registry' do - expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class) - end - - it 'creates an #op_code instance method' do - expect(message.op_code).to eq(described_class::OP_CODE) - end - end - end -end From 1058ccfe932c9c770c95f4b3abb3126f1a5ef473 Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 13:35:24 +0200 Subject: [PATCH 2/6] 3085 --- lib/mongo/operation/aggregate.rb | 1 - lib/mongo/operation/collections_info.rb | 1 - lib/mongo/operation/count.rb | 1 - lib/mongo/operation/create.rb | 1 - lib/mongo/operation/create_index.rb | 1 - lib/mongo/operation/create_user.rb | 1 - lib/mongo/operation/delete.rb | 1 - lib/mongo/operation/distinct.rb | 1 - lib/mongo/operation/drop.rb | 1 - lib/mongo/operation/drop_database.rb | 1 - lib/mongo/operation/drop_index.rb | 1 - lib/mongo/operation/explain.rb | 2 - lib/mongo/operation/explain/legacy.rb | 52 -------- lib/mongo/operation/find.rb | 2 - lib/mongo/operation/find/builder.rb | 1 - lib/mongo/operation/find/builder/legacy.rb | 123 ------------------ lib/mongo/operation/find/legacy.rb | 52 -------- lib/mongo/operation/get_more.rb | 2 - lib/mongo/operation/get_more/legacy.rb | 39 ------ lib/mongo/operation/indexes.rb | 2 - lib/mongo/operation/indexes/legacy.rb | 48 ------- lib/mongo/operation/insert.rb | 1 - lib/mongo/operation/kill_cursors.rb | 1 - lib/mongo/operation/list_collections.rb | 1 - lib/mongo/operation/map_reduce.rb | 1 - lib/mongo/operation/parallel_scan.rb | 1 - lib/mongo/operation/remove_user.rb | 1 - lib/mongo/operation/update.rb | 1 - lib/mongo/operation/update_user.rb | 1 - lib/mongo/operation/users_info.rb | 1 - lib/mongo/operation/write_command.rb | 1 - spec/mongo/operation/delete/command_spec.rb | 115 ----------------- spec/mongo/operation/find/legacy_spec.rb | 131 -------------------- spec/mongo/operation/get_more_spec.rb | 63 ---------- spec/mongo/operation/insert/command_spec.rb | 118 ------------------ spec/mongo/operation/update/command_spec.rb | 122 ------------------ 36 files changed, 893 deletions(-) delete mode 100644 lib/mongo/operation/explain/legacy.rb delete mode 100644 lib/mongo/operation/find/builder/legacy.rb delete mode 100644 lib/mongo/operation/find/legacy.rb delete mode 100644 lib/mongo/operation/get_more/legacy.rb delete mode 100644 lib/mongo/operation/indexes/legacy.rb delete mode 100644 spec/mongo/operation/delete/command_spec.rb delete mode 100644 spec/mongo/operation/find/legacy_spec.rb delete mode 100644 spec/mongo/operation/get_more_spec.rb delete mode 100644 spec/mongo/operation/insert/command_spec.rb delete mode 100644 spec/mongo/operation/update/command_spec.rb diff --git a/lib/mongo/operation/aggregate.rb b/lib/mongo/operation/aggregate.rb index cef9575f3a..08ae1ae989 100644 --- a/lib/mongo/operation/aggregate.rb +++ b/lib/mongo/operation/aggregate.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/aggregate/command' require 'mongo/operation/aggregate/op_msg' require 'mongo/operation/aggregate/result' diff --git a/lib/mongo/operation/collections_info.rb b/lib/mongo/operation/collections_info.rb index 371ace3177..7f05b41e71 100644 --- a/lib/mongo/operation/collections_info.rb +++ b/lib/mongo/operation/collections_info.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/collections_info/command' require 'mongo/operation/collections_info/result' module Mongo diff --git a/lib/mongo/operation/count.rb b/lib/mongo/operation/count.rb index 2ebc6c0e12..c0cd32e4cf 100644 --- a/lib/mongo/operation/count.rb +++ b/lib/mongo/operation/count.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/count/command' require 'mongo/operation/count/op_msg' module Mongo diff --git a/lib/mongo/operation/create.rb b/lib/mongo/operation/create.rb index e5371f940c..3615d03735 100644 --- a/lib/mongo/operation/create.rb +++ b/lib/mongo/operation/create.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/create/command' require 'mongo/operation/create/op_msg' module Mongo diff --git a/lib/mongo/operation/create_index.rb b/lib/mongo/operation/create_index.rb index 0f4482118e..079c04674d 100644 --- a/lib/mongo/operation/create_index.rb +++ b/lib/mongo/operation/create_index.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/create_index/command' require 'mongo/operation/create_index/op_msg' module Mongo diff --git a/lib/mongo/operation/create_user.rb b/lib/mongo/operation/create_user.rb index d426dc7324..fe235bfba2 100644 --- a/lib/mongo/operation/create_user.rb +++ b/lib/mongo/operation/create_user.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/create_user/command' require 'mongo/operation/create_user/op_msg' module Mongo diff --git a/lib/mongo/operation/delete.rb b/lib/mongo/operation/delete.rb index df18238836..dc2c6f9e02 100644 --- a/lib/mongo/operation/delete.rb +++ b/lib/mongo/operation/delete.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/delete/command' require 'mongo/operation/delete/op_msg' require 'mongo/operation/delete/result' require 'mongo/operation/delete/bulk_result' diff --git a/lib/mongo/operation/distinct.rb b/lib/mongo/operation/distinct.rb index 2653a74088..8d6172f146 100644 --- a/lib/mongo/operation/distinct.rb +++ b/lib/mongo/operation/distinct.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/distinct/command' require 'mongo/operation/distinct/op_msg' module Mongo diff --git a/lib/mongo/operation/drop.rb b/lib/mongo/operation/drop.rb index b7467a5ba3..9013160a95 100644 --- a/lib/mongo/operation/drop.rb +++ b/lib/mongo/operation/drop.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/drop/command' require 'mongo/operation/drop/op_msg' module Mongo diff --git a/lib/mongo/operation/drop_database.rb b/lib/mongo/operation/drop_database.rb index be75a27fb5..15c8fe3b50 100644 --- a/lib/mongo/operation/drop_database.rb +++ b/lib/mongo/operation/drop_database.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/drop_database/command' require 'mongo/operation/drop_database/op_msg' module Mongo diff --git a/lib/mongo/operation/drop_index.rb b/lib/mongo/operation/drop_index.rb index ae70369525..e1f70bb999 100644 --- a/lib/mongo/operation/drop_index.rb +++ b/lib/mongo/operation/drop_index.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/drop_index/command' require 'mongo/operation/drop_index/op_msg' module Mongo diff --git a/lib/mongo/operation/explain.rb b/lib/mongo/operation/explain.rb index e4757e19cc..0adfa73e76 100644 --- a/lib/mongo/operation/explain.rb +++ b/lib/mongo/operation/explain.rb @@ -17,8 +17,6 @@ require 'mongo/operation/explain/result' require 'mongo/operation/explain/op_msg' -require 'mongo/operation/explain/command' -require 'mongo/operation/explain/legacy' module Mongo module Operation diff --git a/lib/mongo/operation/explain/legacy.rb b/lib/mongo/operation/explain/legacy.rb deleted file mode 100644 index cd54bc6b2f..0000000000 --- a/lib/mongo/operation/explain/legacy.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2015-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Explain - - # A MongoDB explain command operation sent as a legacy wire protocol message. - # - # @api private - # - # @since 2.0.0 - class Legacy - include Specifiable - include Executable - include ReadPreferenceSupported - include PolymorphicResult - - private - - def message(connection) - if spec[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - - Protocol::Query.new( - db_name, - coll_name, - Find::Builder::Legacy.selector(spec, connection), - options(connection).update( - Find::Builder::Legacy.query_options(spec, connection), - ), - ) - end - end - end - end -end diff --git a/lib/mongo/operation/find.rb b/lib/mongo/operation/find.rb index a4528c015a..ea4d66181f 100644 --- a/lib/mongo/operation/find.rb +++ b/lib/mongo/operation/find.rb @@ -15,9 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/find/command' require 'mongo/operation/find/op_msg' -require 'mongo/operation/find/legacy' require 'mongo/operation/find/result' require 'mongo/operation/find/builder' diff --git a/lib/mongo/operation/find/builder.rb b/lib/mongo/operation/find/builder.rb index c1d8b1fea6..552a93d35e 100644 --- a/lib/mongo/operation/find/builder.rb +++ b/lib/mongo/operation/find/builder.rb @@ -17,5 +17,4 @@ require 'mongo/operation/find/builder/command' require 'mongo/operation/find/builder/flags' -require 'mongo/operation/find/builder/legacy' require 'mongo/operation/find/builder/modifiers' diff --git a/lib/mongo/operation/find/builder/legacy.rb b/lib/mongo/operation/find/builder/legacy.rb deleted file mode 100644 index 47a2e59ad1..0000000000 --- a/lib/mongo/operation/find/builder/legacy.rb +++ /dev/null @@ -1,123 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2015-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Find - module Builder - - # Builds a legacy OP_QUERY specification from options. - # - # @api private - module Legacy - - # Mappings from driver options to legacy server values. - # - # @since 2.2.0 - DRIVER_MAPPINGS = { - comment: '$comment', - explain: '$explain', - hint: '$hint', - max_scan: '$maxScan', - max_time_ms: '$maxTimeMS', - max_value: '$max', - min_value: '$min', - show_disk_loc: '$showDiskLoc', - snapshot: '$snapshot', - sort: '$orderby', - return_key: '$returnKey', - }.freeze - - module_function def selector(spec, connection) - if Lint.enabled? - if spec.keys.any? { |k| String === k } - raise Error::LintError, "The spec must contain symbol keys only" - end - end - - # Server versions that do not have the find command feature - # (versions older than 3.2) do not support the allow_disk_use option - # but perform no validation and will not raise an error if it is - # specified. If the allow_disk_use option is specified, raise an error - # to alert the user. - unless spec[:allow_disk_use].nil? - raise Error::UnsupportedOption.allow_disk_use_error - end - - if spec[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - - modifiers = {} - DRIVER_MAPPINGS.each do |k, server_k| - unless (value = spec[k]).nil? - modifiers[server_k] = value - end - end - - selector = spec[:filter] || BSON::Document.new - # Write nil into rp if not talking to mongos, rather than false - rp = if connection.description.mongos? - read_pref_formatted(spec) - end - if modifiers.any? || rp - selector = {'$query' => selector}.update(modifiers) - - if rp - selector['$readPreference'] = rp - end - end - - selector - end - - module_function def query_options(spec, connection) - query_options = { - project: spec[:projection], - skip: spec[:skip], - limit: spec[:limit], - # batch_size is converted to batchSize by Mongo::Protocol::Query. - batch_size: spec[:batch_size], - } - - unless (flags = Builder::Flags.map_flags(spec)).empty? - query_options[:flags] = ((query_options[:flags] || []) + flags).uniq - end - - query_options - end - - private - - module_function def read_pref_formatted(spec) - if spec[:read_preference] - raise ArgumentError, "Spec cannot include :read_preference here, use :read" - end - - if read = spec[:read] - read_pref = ServerSelector.get(read).to_mongos - Mongo::Lint.validate_camel_case_read_preference(read_pref) - read_pref - else - nil - end - end - end - end - end - end -end diff --git a/lib/mongo/operation/find/legacy.rb b/lib/mongo/operation/find/legacy.rb deleted file mode 100644 index 33989d1b8d..0000000000 --- a/lib/mongo/operation/find/legacy.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require 'mongo/operation/find/legacy/result' - -module Mongo - module Operation - class Find - - # A MongoDB find operation sent as a legacy wire protocol message. - # - # @api private - # - # @since 2.5.2 - class Legacy - include Specifiable - include Executable - include ReadPreferenceSupported - include PolymorphicResult - - private - - def message(connection) - selector = Find::Builder::Legacy.selector(spec, connection) - options = options(connection).update( - Find::Builder::Legacy.query_options(spec, connection), - ) - Protocol::Query.new( - db_name, - coll_name, - selector, - options, - ) - end - end - end - end -end diff --git a/lib/mongo/operation/get_more.rb b/lib/mongo/operation/get_more.rb index 455f8f6394..cc2d95b4ae 100644 --- a/lib/mongo/operation/get_more.rb +++ b/lib/mongo/operation/get_more.rb @@ -16,9 +16,7 @@ # limitations under the License. require 'mongo/operation/get_more/command_builder' -require 'mongo/operation/get_more/command' require 'mongo/operation/get_more/op_msg' -require 'mongo/operation/get_more/legacy' require 'mongo/operation/get_more/result' module Mongo diff --git a/lib/mongo/operation/get_more/legacy.rb b/lib/mongo/operation/get_more/legacy.rb deleted file mode 100644 index e3ac61485f..0000000000 --- a/lib/mongo/operation/get_more/legacy.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class GetMore - - # A MongoDB getMore operation sent as a legacy wire protocol message. - # - # @api private - # - # @since 2.5.2 - class Legacy - include Specifiable - include Executable - - private - - def message(connection) - Protocol::GetMore.new(db_name, coll_name, to_return, cursor_id) - end - end - end - end -end diff --git a/lib/mongo/operation/indexes.rb b/lib/mongo/operation/indexes.rb index e1ead670f1..527f3fa757 100644 --- a/lib/mongo/operation/indexes.rb +++ b/lib/mongo/operation/indexes.rb @@ -15,9 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/indexes/command' require 'mongo/operation/indexes/op_msg' -require 'mongo/operation/indexes/legacy' require 'mongo/operation/indexes/result' module Mongo diff --git a/lib/mongo/operation/indexes/legacy.rb b/lib/mongo/operation/indexes/legacy.rb deleted file mode 100644 index 27ef213f0f..0000000000 --- a/lib/mongo/operation/indexes/legacy.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2014-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Indexes - - # A MongoDB indexes operation sent as a legacy wire protocol message. - # - # @api private - # - # @since 2.5.2 - class Legacy - include Specifiable - include Executable - include ReadPreferenceSupported - - private - - def selector(connection) - { ns: namespace } - end - - def message(connection) - Protocol::Query.new(db_name, Index::COLLECTION, command(connection), options(connection)) - end - - def result_class - Operation::Result - end - end - end - end -end diff --git a/lib/mongo/operation/insert.rb b/lib/mongo/operation/insert.rb index e9df182ccd..948351e5b0 100644 --- a/lib/mongo/operation/insert.rb +++ b/lib/mongo/operation/insert.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/insert/command' require 'mongo/operation/insert/op_msg' require 'mongo/operation/insert/result' require 'mongo/operation/insert/bulk_result' diff --git a/lib/mongo/operation/kill_cursors.rb b/lib/mongo/operation/kill_cursors.rb index fef0cb0597..55efc25dca 100644 --- a/lib/mongo/operation/kill_cursors.rb +++ b/lib/mongo/operation/kill_cursors.rb @@ -16,7 +16,6 @@ # limitations under the License. require 'mongo/operation/kill_cursors/command_builder' -require 'mongo/operation/kill_cursors/command' require 'mongo/operation/kill_cursors/op_msg' module Mongo diff --git a/lib/mongo/operation/list_collections.rb b/lib/mongo/operation/list_collections.rb index 8e50d8884d..c94a242ebd 100644 --- a/lib/mongo/operation/list_collections.rb +++ b/lib/mongo/operation/list_collections.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/list_collections/command' require 'mongo/operation/list_collections/op_msg' require 'mongo/operation/list_collections/result' diff --git a/lib/mongo/operation/map_reduce.rb b/lib/mongo/operation/map_reduce.rb index d77b37a076..a89410887d 100644 --- a/lib/mongo/operation/map_reduce.rb +++ b/lib/mongo/operation/map_reduce.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/map_reduce/command' require 'mongo/operation/map_reduce/op_msg' require 'mongo/operation/map_reduce/result' diff --git a/lib/mongo/operation/parallel_scan.rb b/lib/mongo/operation/parallel_scan.rb index a435bdc922..29fbf1311e 100644 --- a/lib/mongo/operation/parallel_scan.rb +++ b/lib/mongo/operation/parallel_scan.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/parallel_scan/command' require 'mongo/operation/parallel_scan/op_msg' require 'mongo/operation/parallel_scan/result' diff --git a/lib/mongo/operation/remove_user.rb b/lib/mongo/operation/remove_user.rb index f17358c918..175ce2f368 100644 --- a/lib/mongo/operation/remove_user.rb +++ b/lib/mongo/operation/remove_user.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/remove_user/command' require 'mongo/operation/remove_user/op_msg' module Mongo diff --git a/lib/mongo/operation/update.rb b/lib/mongo/operation/update.rb index c97db17aa5..9b4aa12602 100644 --- a/lib/mongo/operation/update.rb +++ b/lib/mongo/operation/update.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/update/command' require 'mongo/operation/update/op_msg' require 'mongo/operation/update/result' require 'mongo/operation/update/bulk_result' diff --git a/lib/mongo/operation/update_user.rb b/lib/mongo/operation/update_user.rb index 498db1a9dc..f64d379919 100644 --- a/lib/mongo/operation/update_user.rb +++ b/lib/mongo/operation/update_user.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/update_user/command' require 'mongo/operation/update_user/op_msg' module Mongo diff --git a/lib/mongo/operation/users_info.rb b/lib/mongo/operation/users_info.rb index 71cae7f82a..23ab06f4ef 100644 --- a/lib/mongo/operation/users_info.rb +++ b/lib/mongo/operation/users_info.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/users_info/command' require 'mongo/operation/users_info/op_msg' require 'mongo/operation/users_info/result' diff --git a/lib/mongo/operation/write_command.rb b/lib/mongo/operation/write_command.rb index 3d882f6157..cad463e8f4 100644 --- a/lib/mongo/operation/write_command.rb +++ b/lib/mongo/operation/write_command.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/write_command/command' require 'mongo/operation/write_command/op_msg' module Mongo diff --git a/spec/mongo/operation/delete/command_spec.rb b/spec/mongo/operation/delete/command_spec.rb deleted file mode 100644 index c189306d8c..0000000000 --- a/spec/mongo/operation/delete/command_spec.rb +++ /dev/null @@ -1,115 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'spec_helper' - -describe Mongo::Operation::Delete::Command do - - let(:write_concern) do - Mongo::WriteConcern.get(w: :majority) - end - - let(:session) { nil } - let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] } - let(:spec) do - { :deletes => deletes, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :write_concern => write_concern, - :ordered => true, - :session => session - } - end - - let(:op) { described_class.new(spec) } - - describe '#initialize' do - - context 'spec' do - - it 'sets the spec' do - expect(op.spec).to eq(spec) - end - end - end - - describe '#==' do - - context 'spec' do - - context 'when two ops have the same specs' do - let(:other) { described_class.new(spec) } - - it 'returns true' do - expect(op).to eq(other) - end - end - - context 'when two ops have different specs' do - let(:other_deletes) { [{:q => { :bar => 1 }, :limit => 1}] } - let(:other_spec) do - { :deletes => other_deletes, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :write_concern => write_concern, - :ordered => true - } - end - let(:other) { described_class.new(other_spec) } - - it 'returns false' do - expect(op).not_to eq(other) - end - end - end - end - - describe 'write concern' do - - context 'when write concern is not specified' do - - let(:spec) do - { :deletes => deletes, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :ordered => true - } - end - - it 'does not include write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to be_nil - end - end - - context 'when write concern is specified' do - - it 'includes write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options) - end - end - end - - describe '#message' do - - context 'when the server does not support OP_MSG' do - max_server_version '3.4' - - let(:expected_selector) do - { - :delete => authorized_collection.name, - :deletes => deletes, - :writeConcern => write_concern.options, - :ordered => true - } - end - - it 'creates the correct query wire protocol message' do - expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name, - '$cmd', - expected_selector, - { limit: -1 } ) - op.send(:message, authorized_primary) - end - end - end -end diff --git a/spec/mongo/operation/find/legacy_spec.rb b/spec/mongo/operation/find/legacy_spec.rb deleted file mode 100644 index f9cf973f3b..0000000000 --- a/spec/mongo/operation/find/legacy_spec.rb +++ /dev/null @@ -1,131 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'spec_helper' - -describe Mongo::Operation::Find::Legacy do - max_server_version '3.4' - - let(:context) { Mongo::Operation::Context.new } - - let(:selector) { { foo: 1 } } - let(:query_options) { {} } - let(:spec) do - { :selector => selector, - :options => query_options, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :read => Mongo::ServerSelector.get - } - end - let(:op) { described_class.new(spec) } - - describe '#initialize' do - - context 'query spec' do - it 'sets the query spec' do - expect(op.spec).to be(spec) - end - end - end - - describe '#==' do - - context 'when two ops have different specs' do - let(:other_spec) do - { :selector => { :a => 1 }, - :options => query_options, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name - } - end - let(:other) { described_class.new(other_spec) } - - it 'returns false' do - expect(op).not_to eq(other) - end - end - end - - describe '#message' do - - let(:query_options) do - { :flags => [ :no_cursor_timeout ]} - end - - let(:query) do - described_class.new(spec) - end - - let(:cluster_single) do - double('cluster').tap do |c| - allow(c).to receive(:single?).and_return(true) - end - end - - let(:message) do - authorized_primary.with_connection do |connection| - query.send(:message, connection) - end - end - - it 'applies the correct flags' do - expect(message.flags).to eq(query_options[:flags]) - end - - context 'when the server is a secondary' do - let(:description) do - double('description').tap do |description| - expect(description).to receive(:mongos?) { false } - expect(description).to receive(:standalone?) { false } - #expect(description).to receive(:load_balancer?) { false } - end - end - - let(:connection) do - double('connection').tap do |conn| - expect(conn).to receive(:description).at_least(:once).and_return(description) - end - end - - let(:secondary_server_single) do - double('secondary_server').tap do |server| - expect(server).to receive(:with_connection).and_yield(connection) - expect(server).to receive(:cluster) { cluster_single } - end - end - - let(:message) do - secondary_server_single.with_connection do |connection| - query.send(:message, connection) - end - end - - before do - allow(connection).to receive(:server) { secondary_server_single } - end - - it 'applies the correct flags' do - expect(message.flags).to eq([ :no_cursor_timeout, :secondary_ok ]) - end - end - - context "when the document contains an 'ok' field" do - - before do - authorized_collection.insert_one(ok: false) - end - - after do - authorized_collection.delete_many - end - - it 'does not raise an exception' do - authorized_primary.with_connection do |connection| - expect(op.execute(connection, context: context)).to be_a(Mongo::Operation::Find::Legacy::Result) - end - end - end - end -end - diff --git a/spec/mongo/operation/get_more_spec.rb b/spec/mongo/operation/get_more_spec.rb deleted file mode 100644 index 7c5bd9bb19..0000000000 --- a/spec/mongo/operation/get_more_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'spec_helper' - -describe Mongo::Operation::GetMore::Legacy do - - let(:to_return) do - 50 - end - - let(:cursor_id) do - 1 - end - - let(:spec) do - { :db_name => SpecConfig.instance.test_db, - :coll_name => TEST_COLL, - :to_return => to_return, - :cursor_id => cursor_id } - end - - let(:op) { described_class.new(spec) } - - let(:context) { Mongo::Operation::Context.new } - - describe '#initialize' do - - it 'sets the spec' do - expect(op.spec).to be(spec) - end - end - - describe '#==' do - - context ' when two ops have different specs' do - let(:other_spec) do - { :db_name => 'test_db', - :coll_name => 'test_coll', - :to_return => 50, - :cursor_id => 2 } - end - let(:other) { described_class.new(other_spec) } - - it 'returns false' do - expect(op).not_to eq(other) - end - end - end - - describe '#message' do - - it 'creates a get more wire protocol message with correct specs' do - expect(Mongo::Protocol::GetMore).to receive(:new).with(SpecConfig.instance.test_db, TEST_COLL, to_return, cursor_id).and_call_original - begin - authorized_primary.with_connection do |connection| - op.execute(connection, context: context) - end - rescue - end - end - end -end diff --git a/spec/mongo/operation/insert/command_spec.rb b/spec/mongo/operation/insert/command_spec.rb deleted file mode 100644 index 930c8fdfa5..0000000000 --- a/spec/mongo/operation/insert/command_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'spec_helper' - -describe Mongo::Operation::Insert::Command do - - let(:documents) { [{ :_id => 1, :foo => 1 }] } - let(:session) { nil } - let(:spec) do - { :documents => documents, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :write_concern => write_concern, - :ordered => true, - :session => session - } - end - - let(:write_concern) do - Mongo::WriteConcern.get(w: :majority) - end - - let(:op) { described_class.new(spec) } - - describe '#initialize' do - - context 'spec' do - - it 'sets the spec' do - expect(op.spec).to eq(spec) - end - end - end - - describe '#==' do - - context 'spec' do - - context 'when two ops have the same specs' do - let(:other) { described_class.new(spec) } - - it 'returns true' do - expect(op).to eq(other) - end - end - - context 'when two ops have different specs' do - let(:other_documents) { [{ :bar => 1 }] } - let(:other_spec) do - { :documents => other_documents, - :db_name => authorized_collection.database.name, - :insert => authorized_collection.name, - :write_concern => write_concern.options, - :ordered => true - } - end - let(:other) { described_class.new(other_spec) } - - it 'returns false' do - expect(op).not_to eq(other) - end - end - end - end - - describe 'write concern' do - # https://jira.mongodb.org/browse/RUBY-2224 - require_no_linting - - context 'when write concern is not specified' do - - let(:spec) do - { :documents => documents, - :db_name => authorized_collection.database.name, - :coll_name => authorized_collection.name, - :ordered => true - } - end - - it 'does not include write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to be_nil - end - end - - context 'when write concern is specified' do - - it 'includes write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options) - end - end - end - - describe '#message' do - # https://jira.mongodb.org/browse/RUBY-2224 - require_no_linting - - context 'when the server does not support OP_MSG' do - max_server_version '3.4' - - let(:expected_selector) do - { :documents => documents, - :insert => authorized_collection.name, - :writeConcern => write_concern.options, - :ordered => true - } - end - - it 'creates a query wire protocol message with correct specs' do - expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name, - '$cmd', - expected_selector, - { limit: -1, validating_keys: true }) - op.send(:message, authorized_primary) - end - end - end -end diff --git a/spec/mongo/operation/update/command_spec.rb b/spec/mongo/operation/update/command_spec.rb deleted file mode 100644 index f2b0c6de46..0000000000 --- a/spec/mongo/operation/update/command_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -require 'spec_helper' - -describe Mongo::Operation::Update::Command do - - let(:updates) { [{:q => { :foo => 1 }, - :u => { :$set => { :bar => 1 } }, - :multi => true, - :upsert => false }] } - - let(:write_concern) do - Mongo::WriteConcern.get(w: :majority) - end - let(:session) { nil } - let(:spec) do - { :updates => updates, - :db_name => SpecConfig.instance.test_db, - :coll_name => TEST_COLL, - :write_concern => write_concern, - :ordered => true, - :session => session - } - end - - let(:op) { described_class.new(spec) } - - describe '#initialize' do - - context 'spec' do - - it 'sets the spec' do - expect(op.spec).to eq(spec) - end - end - end - - describe '#==' do - - context 'spec' do - - context 'when two ops have the same specs' do - let(:other) { described_class.new(spec) } - - it 'returns true' do - expect(op).to eq(other) - end - end - - context 'when two ops have different specs' do - let(:other_updates) { [{:q => { :bar => 1 }, - :u => { :$set => { :bar => 2 } }, - :multi => true, - :upsert => false }] } - let(:other_spec) do - { :updates => other_updates, - :db_name => SpecConfig.instance.test_db, - :coll_name => TEST_COLL, - :write_concern => Mongo::WriteConcern.get(w: :majority), - :ordered => true - } - end - let(:other) { described_class.new(other_spec) } - - it 'returns false' do - expect(op).not_to eq(other) - end - end - end - end - - describe 'write concern' do - # https://jira.mongodb.org/browse/RUBY-2224 - require_no_linting - - context 'when write concern is not specified' do - - let(:spec) do - { :updates => updates, - :db_name => SpecConfig.instance.test_db, - :coll_name => TEST_COLL, - :ordered => true - } - end - - it 'does not include write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to be_nil - end - end - - context 'when write concern is specified' do - - it 'includes write concern in the selector' do - expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options) - end - end - end - - describe '#message' do - # https://jira.mongodb.org/browse/RUBY-2224 - require_no_linting - - context 'when the server does not support OP_MSG' do - max_server_version '3.4' - - let(:expected_selector) do - { - :update => TEST_COLL, - :updates => updates, - :ordered => true, - :writeConcern => write_concern.options - } - end - - it 'creates the correct Command message' do - expect(Mongo::Protocol::Query).to receive(:new).with(SpecConfig.instance.test_db, '$cmd', expected_selector, { limit: -1 }) - op.send(:message, authorized_primary) - end - end - end -end From 00ca475825bcdf1a3ec383e7dcb710d24973a94f Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 13:53:52 +0200 Subject: [PATCH 3/6] 3085 --- lib/mongo/operation/aggregate/command.rb | 55 ----------------- lib/mongo/operation/collections_info.rb | 12 +--- .../operation/collections_info/command.rb | 48 --------------- lib/mongo/operation/count/command.rb | 47 -------------- lib/mongo/operation/create/command.rb | 47 -------------- lib/mongo/operation/create_index/command.rb | 61 ------------------- lib/mongo/operation/create_user/command.rb | 46 -------------- lib/mongo/operation/delete/command.rb | 52 ---------------- lib/mongo/operation/distinct/command.rb | 47 -------------- lib/mongo/operation/drop/command.rb | 41 ------------- lib/mongo/operation/drop_database/command.rb | 41 ------------- lib/mongo/operation/drop_index/command.rb | 45 -------------- lib/mongo/operation/explain/command.rb | 58 ------------------ lib/mongo/operation/find/command.rb | 51 ---------------- lib/mongo/operation/find/legacy/result.rb | 46 -------------- lib/mongo/operation/get_more/command.rb | 43 ------------- lib/mongo/operation/indexes/command.rb | 42 ------------- lib/mongo/operation/insert/command.rb | 55 ----------------- lib/mongo/operation/kill_cursors/command.rb | 48 --------------- .../operation/list_collections/command.rb | 46 -------------- lib/mongo/operation/map_reduce/command.rb | 51 ---------------- lib/mongo/operation/parallel_scan/command.rb | 57 ----------------- lib/mongo/operation/remove_user/command.rb | 46 -------------- lib/mongo/operation/update/command.rb | 53 ---------------- lib/mongo/operation/update_user/command.rb | 45 -------------- lib/mongo/operation/users_info/command.rb | 46 -------------- lib/mongo/operation/write_command/command.rb | 51 ---------------- 27 files changed, 1 insertion(+), 1279 deletions(-) delete mode 100644 lib/mongo/operation/aggregate/command.rb delete mode 100644 lib/mongo/operation/collections_info/command.rb delete mode 100644 lib/mongo/operation/count/command.rb delete mode 100644 lib/mongo/operation/create/command.rb delete mode 100644 lib/mongo/operation/create_index/command.rb delete mode 100644 lib/mongo/operation/create_user/command.rb delete mode 100644 lib/mongo/operation/delete/command.rb delete mode 100644 lib/mongo/operation/distinct/command.rb delete mode 100644 lib/mongo/operation/drop/command.rb delete mode 100644 lib/mongo/operation/drop_database/command.rb delete mode 100644 lib/mongo/operation/drop_index/command.rb delete mode 100644 lib/mongo/operation/explain/command.rb delete mode 100644 lib/mongo/operation/find/command.rb delete mode 100644 lib/mongo/operation/find/legacy/result.rb delete mode 100644 lib/mongo/operation/get_more/command.rb delete mode 100644 lib/mongo/operation/indexes/command.rb delete mode 100644 lib/mongo/operation/insert/command.rb delete mode 100644 lib/mongo/operation/kill_cursors/command.rb delete mode 100644 lib/mongo/operation/list_collections/command.rb delete mode 100644 lib/mongo/operation/map_reduce/command.rb delete mode 100644 lib/mongo/operation/parallel_scan/command.rb delete mode 100644 lib/mongo/operation/remove_user/command.rb delete mode 100644 lib/mongo/operation/update/command.rb delete mode 100644 lib/mongo/operation/update_user/command.rb delete mode 100644 lib/mongo/operation/users_info/command.rb delete mode 100644 lib/mongo/operation/write_command/command.rb diff --git a/lib/mongo/operation/aggregate/command.rb b/lib/mongo/operation/aggregate/command.rb deleted file mode 100644 index 9239d2feaa..0000000000 --- a/lib/mongo/operation/aggregate/command.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Aggregate - - # A MongoDB aggregate operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include PolymorphicResult - include ReadPreferenceSupported - include WriteConcernSupported - include Limited - - private - - def selector(connection) - super.tap do |selector| - if selector[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - end - end - - def write_concern_supported?(connection) - connection.features.collation_enabled? - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/collections_info.rb b/lib/mongo/operation/collections_info.rb index 7f05b41e71..18ed786760 100644 --- a/lib/mongo/operation/collections_info.rb +++ b/lib/mongo/operation/collections_info.rb @@ -33,17 +33,7 @@ class CollectionsInfo private def final_operation(connection) - op_class = if connection.features.list_collections_enabled? - if connection.features.op_msg_enabled? - ListCollections::OpMsg - else - ListCollections::Command - end - else - CollectionsInfo::Command - end - - op_class.new(spec) + ListCollections::OpMsg.new(spec) end end end diff --git a/lib/mongo/operation/collections_info/command.rb b/lib/mongo/operation/collections_info/command.rb deleted file mode 100644 index fba3b1b886..0000000000 --- a/lib/mongo/operation/collections_info/command.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class CollectionsInfo - - # A MongoDB collectionInfo operation sent as a command message. - # - # @api private - class Command - include Specifiable - include Executable - include ReadPreferenceSupported - include PolymorphicResult - - private - - def get_result(connection, context, options = {}) - # This is a Mongo::Operation::CollectionsInfo::Result - Result.new(*dispatch_message(connection, context), db_name) - end - - def selector(connection) - {} - end - - def message(connection) - Protocol::Query.new(db_name, Database::NAMESPACES, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/count/command.rb b/lib/mongo/operation/count/command.rb deleted file mode 100644 index a2d38016bd..0000000000 --- a/lib/mongo/operation/count/command.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Count - - # A MongoDB count operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - - private - - def selector(connection) - selector = spec[:selector] - selector = apply_collation(selector, connection, spec[:collation]) - selector - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/create/command.rb b/lib/mongo/operation/create/command.rb deleted file mode 100644 index 2cef393c9d..0000000000 --- a/lib/mongo/operation/create/command.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Create - - # A MongoDB create collection operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def selector(connection) - selector = spec[:selector] - selector = apply_collation(selector, connection, spec[:collation]) - selector - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/create_index/command.rb b/lib/mongo/operation/create_index/command.rb deleted file mode 100644 index 5bbf6a8c5b..0000000000 --- a/lib/mongo/operation/create_index/command.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class CreateIndex - - # A MongoDB createindex operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def selector(connection) - indexes.each do |index| - if index[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - end - - { - createIndexes: coll_name, - indexes: indexes, - }.tap do |selector| - if commit_quorum = spec[:commit_quorum] - unless connection.features.commit_quorum_enabled? - raise Error::UnsupportedOption.commit_quorum_error - end - selector[:commitQuorum] = commit_quorum - end - end - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/create_user/command.rb b/lib/mongo/operation/create_user/command.rb deleted file mode 100644 index 032cd6c629..0000000000 --- a/lib/mongo/operation/create_user/command.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class CreateUser - - # A MongoDB createuser operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include WriteConcernSupported - - private - - def selector(connection) - { :createUser => user.name }.merge(user.spec) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/delete/command.rb b/lib/mongo/operation/delete/command.rb deleted file mode 100644 index e1e3ea485d..0000000000 --- a/lib/mongo/operation/delete/command.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Delete - - # A MongoDB delete operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - include ExecutableNoValidate - include PolymorphicResult - include Validatable - - private - - def selector(connection) - { - delete: coll_name, - deletes: validate_updates(connection, send(IDENTIFIER)), - ordered: ordered?, - } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/distinct/command.rb b/lib/mongo/operation/distinct/command.rb deleted file mode 100644 index 091ae0586c..0000000000 --- a/lib/mongo/operation/distinct/command.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Distinct - - # A MongoDB distinct operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - - private - - def selector(connection) - selector = spec[:selector] - selector = apply_collation(selector, connection, spec[:collation]) - selector - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/drop/command.rb b/lib/mongo/operation/drop/command.rb deleted file mode 100644 index 862bb2ff97..0000000000 --- a/lib/mongo/operation/drop/command.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Drop - - # A MongoDB drop collection operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/drop_database/command.rb b/lib/mongo/operation/drop_database/command.rb deleted file mode 100644 index 983090af79..0000000000 --- a/lib/mongo/operation/drop_database/command.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class DropDatabase - - # A MongoDB dropdatabase operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/drop_index/command.rb b/lib/mongo/operation/drop_index/command.rb deleted file mode 100644 index f78c634f8b..0000000000 --- a/lib/mongo/operation/drop_index/command.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class DropIndex - - # A MongoDB dropindex operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def selector(connection) - { :dropIndexes => coll_name, :index => index_name } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/explain/command.rb b/lib/mongo/operation/explain/command.rb deleted file mode 100644 index 05c2783be8..0000000000 --- a/lib/mongo/operation/explain/command.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Explain - - # A MongoDB explain command operation sent as a command message. - # - # @api private - # - # @since 2.0.0 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def selector(connection) - # The mappings are BSON::Documents and as such store keys as - # strings, the spec here has symbol keys. - spec = BSON::Document.new(self.spec) - - if spec[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - - { - explain: { - find: coll_name, - }.update(Find::Builder::Command.selector(spec, connection)), - }.update(spec[:explain] || {}) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/find/command.rb b/lib/mongo/operation/find/command.rb deleted file mode 100644 index 181b557c10..0000000000 --- a/lib/mongo/operation/find/command.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Find - - # A MongoDB find operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def selector(connection) - # The mappings are BSON::Documents and as such store keys as - # strings, the spec here has symbol keys - spec = BSON::Document.new(self.spec) - { - find: coll_name, - }.update(Find::Builder::Command.selector(spec, connection)) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/find/legacy/result.rb b/lib/mongo/operation/find/legacy/result.rb deleted file mode 100644 index d4d0068661..0000000000 --- a/lib/mongo/operation/find/legacy/result.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2014-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Find - class Legacy - - # Defines custom behavior of results for a query. - # - # @since 2.1.0 - # @api semiprivate - class Result < Operation::Result - include Operation::Result::UseLegacyErrorParser - - # Determine if the query was a success. - # - # @example Was the query successful? - # result.successful? - # - # @return [ true, false ] If the query was successful. - # - # @since 2.0.0 - # @api public - def successful? - !query_failure? - end - end - end - end - end -end diff --git a/lib/mongo/operation/get_more/command.rb b/lib/mongo/operation/get_more/command.rb deleted file mode 100644 index 9188d20e10..0000000000 --- a/lib/mongo/operation/get_more/command.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class GetMore - - # A MongoDB getMore operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - include CommandBuilder - - private - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/indexes/command.rb b/lib/mongo/operation/indexes/command.rb deleted file mode 100644 index 0fdf19ee20..0000000000 --- a/lib/mongo/operation/indexes/command.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Indexes - - # A MongoDB indexes operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/insert/command.rb b/lib/mongo/operation/insert/command.rb deleted file mode 100644 index c403d7c80c..0000000000 --- a/lib/mongo/operation/insert/command.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Insert - - # A MongoDB insert operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include ExecutableNoValidate - include Idable - include Limited - include WriteConcernSupported - include BypassDocumentValidation - - private - - def get_result(connection, context, options = {}) - # This is a Mongo::Operation::Insert::Result - Result.new(*dispatch_message(connection, context), @ids) - end - - def selector(connection) - { insert: coll_name, - documents: send(IDENTIFIER), - ordered: ordered? } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/kill_cursors/command.rb b/lib/mongo/operation/kill_cursors/command.rb deleted file mode 100644 index 2e12d3ef69..0000000000 --- a/lib/mongo/operation/kill_cursors/command.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class KillCursors - - # A MongoDB killcursors operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include CommandBuilder - - private - - def selector(connection) - { - killCursors: coll_name, - cursors: int64_cursor_ids, - } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, selector(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/list_collections/command.rb b/lib/mongo/operation/list_collections/command.rb deleted file mode 100644 index de89b72617..0000000000 --- a/lib/mongo/operation/list_collections/command.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class ListCollections - - # A MongoDB listcollections operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def selector(connection) - (spec[SELECTOR] || {}).merge(listCollections: 1) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/map_reduce/command.rb b/lib/mongo/operation/map_reduce/command.rb deleted file mode 100644 index 116dc64601..0000000000 --- a/lib/mongo/operation/map_reduce/command.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class MapReduce - - # A MongoDB mapreduce operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include WriteConcernSupported - include PolymorphicResult - - private - - def selector(connection) - super.tap do |selector| - if selector[:collation] && !connection.features.collation_enabled? - raise Error::UnsupportedCollation - end - end - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/parallel_scan/command.rb b/lib/mongo/operation/parallel_scan/command.rb deleted file mode 100644 index c6b36b8dc9..0000000000 --- a/lib/mongo/operation/parallel_scan/command.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class ParallelScan - - # A MongoDB parallelscan operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def selector(connection) - sel = { :parallelCollectionScan => coll_name, :numCursors => cursor_count } - if read_concern - sel[:readConcern] = Options::Mapper.transform_values_to_strings( - read_concern) - end - sel[:maxTimeMS] = max_time_ms if max_time_ms - add_read_preference_legacy(sel, connection) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end - - - - - diff --git a/lib/mongo/operation/remove_user/command.rb b/lib/mongo/operation/remove_user/command.rb deleted file mode 100644 index 121078223e..0000000000 --- a/lib/mongo/operation/remove_user/command.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class RemoveUser - - # A MongoDB removeuser operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include WriteConcernSupported - - private - - def selector(connection) - { :dropUser => user_name } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/update/command.rb b/lib/mongo/operation/update/command.rb deleted file mode 100644 index 8e02bbbfd2..0000000000 --- a/lib/mongo/operation/update/command.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Update - - # A MongoDB update operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - include BypassDocumentValidation - include ExecutableNoValidate - include PolymorphicResult - include Validatable - - private - - def selector(connection) - { - update: coll_name, - updates: validate_updates(connection, send(IDENTIFIER)), - ordered: ordered?, - } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/update_user/command.rb b/lib/mongo/operation/update_user/command.rb deleted file mode 100644 index 874c9837ca..0000000000 --- a/lib/mongo/operation/update_user/command.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class UpdateUser - - # A MongoDB updateuser operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include WriteConcernSupported - - private - - def selector(connection) - { :updateUser => user.name }.merge(user.spec) - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/users_info/command.rb b/lib/mongo/operation/users_info/command.rb deleted file mode 100644 index 9da27cca65..0000000000 --- a/lib/mongo/operation/users_info/command.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class UsersInfo - - # A MongoDB usersinfo operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include PolymorphicResult - - private - - def selector(connection) - { :usersInfo => user_name } - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/write_command/command.rb b/lib/mongo/operation/write_command/command.rb deleted file mode 100644 index b97e47d8f1..0000000000 --- a/lib/mongo/operation/write_command/command.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2021 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class WriteCommand - - # A MongoDB write command operation sent as a command message. - # - # @api private - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - include Validatable - - private - - def selector(connection) - super.tap do |selector| - if selector.key?(:findAndModify) - validate_find_options(connection, selector) - end - if wc = spec[:write_concern] - selector[:writeConcern] = wc.options - end - end - end - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end From 9bc9e857387d53a22d6dbd5c97e1d07dfa7258df Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 16:49:41 +0200 Subject: [PATCH 4/6] 3085 --- lib/mongo/operation.rb | 4 +- lib/mongo/operation/aggregate.rb | 2 +- lib/mongo/operation/collections_info.rb | 3 +- lib/mongo/operation/command.rb | 3 +- lib/mongo/operation/command/command.rb | 41 ----------------- lib/mongo/operation/count.rb | 2 +- lib/mongo/operation/create.rb | 2 +- lib/mongo/operation/create_index.rb | 2 +- lib/mongo/operation/create_user.rb | 2 +- lib/mongo/operation/distinct.rb | 2 +- lib/mongo/operation/drop.rb | 2 +- lib/mongo/operation/drop_database.rb | 2 +- lib/mongo/operation/drop_index.rb | 2 +- lib/mongo/operation/explain.rb | 2 +- lib/mongo/operation/find.rb | 2 +- lib/mongo/operation/get_more.rb | 2 +- lib/mongo/operation/indexes.rb | 16 +------ lib/mongo/operation/kill_cursors.rb | 2 +- lib/mongo/operation/list_collections.rb | 2 +- lib/mongo/operation/map_reduce.rb | 2 +- lib/mongo/operation/parallel_scan.rb | 2 +- lib/mongo/operation/remove_user.rb | 2 +- ...phic_operation.rb => op_msg_executable.rb} | 17 ++++--- .../operation/shared/op_msg_or_command.rb | 41 ----------------- .../shared/op_msg_or_find_command.rb | 44 ------------------- lib/mongo/operation/update_user.rb | 2 +- lib/mongo/operation/users_info.rb | 2 +- lib/mongo/operation/write_command.rb | 2 +- 28 files changed, 35 insertions(+), 174 deletions(-) delete mode 100644 lib/mongo/operation/command/command.rb rename lib/mongo/operation/shared/{polymorphic_operation.rb => op_msg_executable.rb} (82%) delete mode 100644 lib/mongo/operation/shared/op_msg_or_command.rb delete mode 100644 lib/mongo/operation/shared/op_msg_or_find_command.rb diff --git a/lib/mongo/operation.rb b/lib/mongo/operation.rb index 1d345ad54c..2c494bffba 100644 --- a/lib/mongo/operation.rb +++ b/lib/mongo/operation.rb @@ -9,7 +9,6 @@ require 'mongo/operation/shared/executable_no_validate' require 'mongo/operation/shared/executable_transaction_label' require 'mongo/operation/shared/polymorphic_lookup' -require 'mongo/operation/shared/polymorphic_operation' require 'mongo/operation/shared/polymorphic_result' require 'mongo/operation/shared/read_preference_supported' require 'mongo/operation/shared/bypass_document_validation' @@ -22,8 +21,7 @@ require 'mongo/operation/shared/specifiable' require 'mongo/operation/shared/validatable' require 'mongo/operation/shared/object_id_generator' -require 'mongo/operation/shared/op_msg_or_command' -require 'mongo/operation/shared/op_msg_or_find_command' +require 'mongo/operation/shared/op_msg_executable' require 'mongo/operation/op_msg_base' require 'mongo/operation/command' diff --git a/lib/mongo/operation/aggregate.rb b/lib/mongo/operation/aggregate.rb index 08ae1ae989..98084df678 100644 --- a/lib/mongo/operation/aggregate.rb +++ b/lib/mongo/operation/aggregate.rb @@ -32,7 +32,7 @@ module Operation # @since 2.0.0 class Aggregate include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/collections_info.rb b/lib/mongo/operation/collections_info.rb index 18ed786760..9375a777af 100644 --- a/lib/mongo/operation/collections_info.rb +++ b/lib/mongo/operation/collections_info.rb @@ -27,8 +27,7 @@ module Operation # @since 2.0.0 class CollectionsInfo include Specifiable - include PolymorphicOperation - include PolymorphicLookup + include OpMsgExecutable private diff --git a/lib/mongo/operation/command.rb b/lib/mongo/operation/command.rb index 2939247266..998f58899b 100644 --- a/lib/mongo/operation/command.rb +++ b/lib/mongo/operation/command.rb @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'mongo/operation/command/command' require 'mongo/operation/command/op_msg' module Mongo @@ -28,7 +27,7 @@ module Operation # @since 2.0.0 class Command include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/command/command.rb b/lib/mongo/operation/command/command.rb deleted file mode 100644 index 88e0ea444b..0000000000 --- a/lib/mongo/operation/command/command.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - class Command - - # A MongoDB command operation sent as a command message. - # - # @api private - # - # @since 2.5.2 - class Command - include Specifiable - include Executable - include Limited - include ReadPreferenceSupported - - private - - def message(connection) - Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection)) - end - end - end - end -end diff --git a/lib/mongo/operation/count.rb b/lib/mongo/operation/count.rb index c0cd32e4cf..92601c8086 100644 --- a/lib/mongo/operation/count.rb +++ b/lib/mongo/operation/count.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class Count include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/create.rb b/lib/mongo/operation/create.rb index 3615d03735..af266f268a 100644 --- a/lib/mongo/operation/create.rb +++ b/lib/mongo/operation/create.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class Create include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/create_index.rb b/lib/mongo/operation/create_index.rb index 079c04674d..900f3025d1 100644 --- a/lib/mongo/operation/create_index.rb +++ b/lib/mongo/operation/create_index.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class CreateIndex include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/create_user.rb b/lib/mongo/operation/create_user.rb index fe235bfba2..e27ec9d61e 100644 --- a/lib/mongo/operation/create_user.rb +++ b/lib/mongo/operation/create_user.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class CreateUser include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/distinct.rb b/lib/mongo/operation/distinct.rb index 8d6172f146..46995b4ef3 100644 --- a/lib/mongo/operation/distinct.rb +++ b/lib/mongo/operation/distinct.rb @@ -27,7 +27,7 @@ module Operation # @since 2.5.0 class Distinct include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/drop.rb b/lib/mongo/operation/drop.rb index 9013160a95..b5b29a26b3 100644 --- a/lib/mongo/operation/drop.rb +++ b/lib/mongo/operation/drop.rb @@ -27,7 +27,7 @@ module Operation # @since 2.4.0 class Drop include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/drop_database.rb b/lib/mongo/operation/drop_database.rb index 15c8fe3b50..db00a738c3 100644 --- a/lib/mongo/operation/drop_database.rb +++ b/lib/mongo/operation/drop_database.rb @@ -27,7 +27,7 @@ module Operation # @since 2.4.0 class DropDatabase include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/drop_index.rb b/lib/mongo/operation/drop_index.rb index e1f70bb999..493a911f38 100644 --- a/lib/mongo/operation/drop_index.rb +++ b/lib/mongo/operation/drop_index.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class DropIndex include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/explain.rb b/lib/mongo/operation/explain.rb index 0adfa73e76..50a61f2fcf 100644 --- a/lib/mongo/operation/explain.rb +++ b/lib/mongo/operation/explain.rb @@ -28,7 +28,7 @@ module Operation # @since 2.5.0 class Explain include Specifiable - include OpMsgOrFindCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/find.rb b/lib/mongo/operation/find.rb index ea4d66181f..533a6e00a6 100644 --- a/lib/mongo/operation/find.rb +++ b/lib/mongo/operation/find.rb @@ -29,7 +29,7 @@ module Operation # @since 2.0.0 class Find include Specifiable - include OpMsgOrFindCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/get_more.rb b/lib/mongo/operation/get_more.rb index cc2d95b4ae..b7ae7ae5c7 100644 --- a/lib/mongo/operation/get_more.rb +++ b/lib/mongo/operation/get_more.rb @@ -29,7 +29,7 @@ module Operation # @since 2.5.0 class GetMore include Specifiable - include OpMsgOrFindCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/indexes.rb b/lib/mongo/operation/indexes.rb index 527f3fa757..779bee85aa 100644 --- a/lib/mongo/operation/indexes.rb +++ b/lib/mongo/operation/indexes.rb @@ -28,21 +28,7 @@ module Operation # @since 2.0.0 class Indexes include Specifiable - include PolymorphicOperation - include PolymorphicLookup - - private - - def final_operation(connection) - cls = if connection.features.op_msg_enabled? - polymorphic_class(self.class.name, :OpMsg) - elsif connection.features.list_indexes_enabled? - polymorphic_class(self.class.name, :Command) - else - polymorphic_class(self.class.name, :Legacy) - end - cls.new(spec) - end + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/kill_cursors.rb b/lib/mongo/operation/kill_cursors.rb index 55efc25dca..17c5b1742c 100644 --- a/lib/mongo/operation/kill_cursors.rb +++ b/lib/mongo/operation/kill_cursors.rb @@ -28,7 +28,7 @@ module Operation # @since 2.0.0 class KillCursors include Specifiable - include OpMsgOrFindCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/list_collections.rb b/lib/mongo/operation/list_collections.rb index c94a242ebd..9a2b81c440 100644 --- a/lib/mongo/operation/list_collections.rb +++ b/lib/mongo/operation/list_collections.rb @@ -28,7 +28,7 @@ module Operation # @since 2.0.0 class ListCollections include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/map_reduce.rb b/lib/mongo/operation/map_reduce.rb index a89410887d..90f2af74f6 100644 --- a/lib/mongo/operation/map_reduce.rb +++ b/lib/mongo/operation/map_reduce.rb @@ -28,7 +28,7 @@ module Operation # @since 2.5.0 class MapReduce include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/parallel_scan.rb b/lib/mongo/operation/parallel_scan.rb index 29fbf1311e..3e9aea4106 100644 --- a/lib/mongo/operation/parallel_scan.rb +++ b/lib/mongo/operation/parallel_scan.rb @@ -28,7 +28,7 @@ module Operation # @since 2.0.0 class ParallelScan include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/remove_user.rb b/lib/mongo/operation/remove_user.rb index 175ce2f368..e704a02ed8 100644 --- a/lib/mongo/operation/remove_user.rb +++ b/lib/mongo/operation/remove_user.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class RemoveUser include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/shared/polymorphic_operation.rb b/lib/mongo/operation/shared/op_msg_executable.rb similarity index 82% rename from lib/mongo/operation/shared/polymorphic_operation.rb rename to lib/mongo/operation/shared/op_msg_executable.rb index 1786bd4c4d..345e905f13 100644 --- a/lib/mongo/operation/shared/polymorphic_operation.rb +++ b/lib/mongo/operation/shared/op_msg_executable.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # encoding: utf-8 -# Copyright (C) 2021 MongoDB Inc. +# Copyright (C) 2018-2020 MongoDB Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,11 +18,11 @@ module Mongo module Operation - # Shared behavior of implementing an operation differently based on - # the server that will be executing the operation. + # Shared behavior of executing the operation as an OpMsg. # # @api private - module PolymorphicOperation + module OpMsgExecutable + include PolymorphicLookup # Execute the operation. # @@ -46,8 +46,13 @@ def execute(server, context:, options: {}) # # @return [ Mongo::Operation::Result ] The operation result. def execute_with_connection(connection, context:, options: {}) - operation = final_operation(connection) - operation.execute(connection, context: context, options: options) + final_operation.execute(connection, context: context, options: options) + end + + private + + def final_operation + polymorphic_class(self.class.name, :OpMsg).new(spec) end end end diff --git a/lib/mongo/operation/shared/op_msg_or_command.rb b/lib/mongo/operation/shared/op_msg_or_command.rb deleted file mode 100644 index 6716237e53..0000000000 --- a/lib/mongo/operation/shared/op_msg_or_command.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - - # Shared behavior of executing the operation as an OpMsg when supported - # or as a Command otherwise. - # - # @api private - module OpMsgOrCommand - include PolymorphicOperation - include PolymorphicLookup - - private - - def final_operation(connection) - cls = if connection.features.op_msg_enabled? - polymorphic_class(self.class.name, :OpMsg) - else - polymorphic_class(self.class.name, :Command) - end - cls.new(spec) - end - end - end -end diff --git a/lib/mongo/operation/shared/op_msg_or_find_command.rb b/lib/mongo/operation/shared/op_msg_or_find_command.rb deleted file mode 100644 index 6084d299ba..0000000000 --- a/lib/mongo/operation/shared/op_msg_or_find_command.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true -# encoding: utf-8 - -# Copyright (C) 2018-2020 MongoDB Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module Mongo - module Operation - - # Shared behavior of executing the operation as an OpMsg when supported, - # as a Command when find command is supported by the server, and as - # Legacy otherwise. - # - # @api private - module OpMsgOrFindCommand - include PolymorphicOperation - include PolymorphicLookup - - private - - def final_operation(connection) - cls = if connection.features.op_msg_enabled? - polymorphic_class(self.class.name, :OpMsg) - elsif connection.features.find_command_enabled? - polymorphic_class(self.class.name, :Command) - else - polymorphic_class(self.class.name, :Legacy) - end - cls.new(spec) - end - end - end -end diff --git a/lib/mongo/operation/update_user.rb b/lib/mongo/operation/update_user.rb index f64d379919..598f1f1552 100644 --- a/lib/mongo/operation/update_user.rb +++ b/lib/mongo/operation/update_user.rb @@ -27,7 +27,7 @@ module Operation # @since 2.0.0 class UpdateUser include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/users_info.rb b/lib/mongo/operation/users_info.rb index 23ab06f4ef..3a1e63422c 100644 --- a/lib/mongo/operation/users_info.rb +++ b/lib/mongo/operation/users_info.rb @@ -28,7 +28,7 @@ module Operation # @since 2.0.0 class UsersInfo include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end diff --git a/lib/mongo/operation/write_command.rb b/lib/mongo/operation/write_command.rb index cad463e8f4..6e322e4d94 100644 --- a/lib/mongo/operation/write_command.rb +++ b/lib/mongo/operation/write_command.rb @@ -25,7 +25,7 @@ module Operation # @api private class WriteCommand include Specifiable - include OpMsgOrCommand + include OpMsgExecutable end end end From e554ddf32ac7ef0ee10c1405d2fb833ad4370e34 Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 17:04:27 +0200 Subject: [PATCH 5/6] 3085 --- lib/mongo/operation/collections_info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/operation/collections_info.rb b/lib/mongo/operation/collections_info.rb index 9375a777af..370334f2a7 100644 --- a/lib/mongo/operation/collections_info.rb +++ b/lib/mongo/operation/collections_info.rb @@ -31,7 +31,7 @@ class CollectionsInfo private - def final_operation(connection) + def final_operation ListCollections::OpMsg.new(spec) end end From 682bf4e7e2afc1d7108de808a699a7b6322cf425 Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Fri, 26 Aug 2022 17:16:08 +0200 Subject: [PATCH 6/6] 3085 --- spec/integration/command_spec.rb | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/spec/integration/command_spec.rb b/spec/integration/command_spec.rb index 9b3237df72..8f78137823 100644 --- a/spec/integration/command_spec.rb +++ b/spec/integration/command_spec.rb @@ -12,7 +12,7 @@ let(:payload) do server.with_connection do |connection| - command.send(:final_operation, connection).send(:message, connection).payload.dup.tap do |payload| + command.send(:final_operation).send(:message, connection).payload.dup.tap do |payload| if payload['request_id'].is_a?(Integer) payload['request_id'] = 42 end @@ -150,28 +150,6 @@ expect(payload).to eq(expected_payload) end end - - # Servers using legacy wire protocol message do not have $db in payload. - # $db is added to the payload later when the command monitoring event is - # published. - context 'pre-OP_MSG servers' do - max_server_version '3.4' - - let(:expected_payload) do - { - 'command' => { - 'find' => 'collection_name', - }, - 'command_name' => 'find', - 'database_name' => 'foo', - 'request_id' => 42, - } - end - - it 'returns expected payload' do - expect(payload).to eq(expected_payload) - end - end end end