class Mongo::Protocol::Insert::Upconverter
Converts legacy insert messages to the appropriare OP_COMMAND style message.
@since 2.1.0
Constants
- DOCUMENTS
Documents field constant.
@since 2.1.0
- INSERT
Insert
field constant.@since 2.1.0
- WRITE_CONCERN
Write concern field constant.
@since 2.1.0
Attributes
collection[R]
@return [ String ] collection The name of the collection.
documents[R]
@return [ Array<BSON::Document> ] documents The documents to insert.
options[R]
@return [ Hash ] options The options.
Public Class Methods
new(collection, documents, options)
click to toggle source
Instantiate the upconverter.
@example Instantiate the upconverter.
Upconverter.new('users', documents)
@param [ String ] collection The name of the collection. @param [ Array<BSON::Document> ] documents The documents. @param [ Hash ] options The options.
@since 2.1.0
# File lib/mongo/protocol/insert.rb, line 149 def initialize(collection, documents, options) @collection = collection @documents = documents @options = options end
Public Instance Methods
command()
click to toggle source
Get the upconverted command.
@example Get the command.
upconverter.command
@return [ BSON::Document ] The upconverted command.
@since 2.1.0
# File lib/mongo/protocol/insert.rb, line 163 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