lib/mongo/protocol/get_more.rb in mongo-2.1.0.beta vs lib/mongo/protocol/get_more.rb in mongo-2.1.0.rc0
- old
+ new
@@ -39,10 +39,11 @@
def initialize(database, collection, number_to_return, cursor_id)
@database = database
@namespace = "#{database}.#{collection}"
@number_to_return = number_to_return
@cursor_id = cursor_id
+ @upconverter = Upconverter.new(collection, cursor_id, number_to_return)
end
# Return the event payload for monitoring.
#
# @example Return the event payload.
@@ -51,13 +52,13 @@
# @return [ Hash ] The event payload.
#
# @since 2.1.0
def payload
{
- command_name: 'getmore',
+ command_name: 'getMore',
database_name: @database,
- command: { cursor_id: cursor_id, number_to_return: number_to_return },
+ command: upconverter.command,
request_id: request_id
}
end
# Get more messages require replies from the database.
@@ -72,10 +73,12 @@
true
end
private
+ attr_reader :upconverter
+
# The operation code required to specify a GetMore message.
# @return [Fixnum] the operation code.
def op_code
2005
end
@@ -92,8 +95,57 @@
field :number_to_return, Int32
# @!attribute
# @return [Fixnum] The cursor id to get more documents from.
field :cursor_id, Int64
+
+ # Converts legacy getmore messages to the appropriare OP_COMMAND style
+ # message.
+ #
+ # @since 2.1.0
+ class Upconverter
+
+ # @return [ String ] collection The name of the collection.
+ attr_reader :collection
+
+ # @return [ Integer ] cursor_id The cursor id.
+ attr_reader :cursor_id
+
+ # @return [ Integer ] number_to_return The number of docs to return.
+ attr_reader :number_to_return
+
+ # Instantiate the upconverter.
+ #
+ # @example Instantiate the upconverter.
+ # Upconverter.new('users', 1, 1)
+ #
+ # @param [ String ] collection The name of the collection.
+ # @param [ Integer ] cursor_id The cursor id.
+ # @param [ Integer ] number_to_return The number of documents to
+ # return.
+ #
+ # @since 2.1.0
+ def initialize(collection, cursor_id, number_to_return)
+ @collection = collection
+ @cursor_id = cursor_id
+ @number_to_return = number_to_return
+ end
+
+ # Get the upconverted command.
+ #
+ # @example Get the command.
+ # upconverter.command
+ #
+ # @return [ BSON::Document ] The upconverted command.
+ #
+ # @since 2.1.0
+ def command
+ BSON::Document.new(
+ getMore: cursor_id,
+ batchSize: number_to_return,
+ collection: collection
+ )
+ end
+ end
end
end
end