Class: Mongo::Protocol::Insert::Upconverter

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-master/lib/mongo/protocol/insert.rb

Overview

Converts legacy insert messages to the appropriare OP_COMMAND style message.

Since:

  • 2.1.0

Constant Summary collapse

INSERT =

Insert field constant.

Since:

  • 2.1.0

'insert'.freeze
DOCUMENTS =

Documents field constant.

Since:

  • 2.1.0

'documents'.freeze
WRITE_CONCERN =

Write concern field constant.

Since:

  • 2.1.0

'writeConcern'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, documents, options) ⇒ Upconverter

Instantiate the upconverter.

Examples:

Instantiate the upconverter.

Upconverter.new('users', documents)

Parameters:

  • collection (String)

    The name of the collection.

  • documents (Array<BSON::Document>)

    The documents.

  • options (Hash)

    The options.

Since:

  • 2.1.0



154
155
156
157
158
# File 'build/ruby-driver-master/lib/mongo/protocol/insert.rb', line 154

def initialize(collection, documents, options)
  @collection = collection
  @documents = documents
  @options = options
end

Instance Attribute Details

#collectionString (readonly)

Returns collection The name of the collection.

Returns:

  • (String)

    collection The name of the collection.

Since:

  • 2.1.0



136
137
138
# File 'build/ruby-driver-master/lib/mongo/protocol/insert.rb', line 136

def collection
  @collection
end

#documentsArray<BSON::Document> (readonly)

Returns documents The documents to insert.

Returns:

  • (Array<BSON::Document>)

    documents The documents to insert.

Since:

  • 2.1.0



139
140
141
# File 'build/ruby-driver-master/lib/mongo/protocol/insert.rb', line 139

def documents
  @documents
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.1.0



142
143
144
# File 'build/ruby-driver-master/lib/mongo/protocol/insert.rb', line 142

def options
  @options
end

Instance Method Details

#commandBSON::Document

Get the upconverted command.

Examples:

Get the command.

upconverter.command

Returns:

  • (BSON::Document)

    The upconverted command.

Since:

  • 2.1.0



168
169
170
171
172
173
174
175
# File 'build/ruby-driver-master/lib/mongo/protocol/insert.rb', line 168

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