class Mongo::Operation::Write::Command::Insert

A MongoDB insert write command operation.

@example Create an insert write command operation.

Write::Command::Insert.new({
  :documents => [{ :foo => 1 }],
  :db_name => 'test',
  :coll_name => 'test_coll',
  :write_concern => write_concern,
  :ordered => true
})

@since 2.0.0

Private Instance Methods

message(server) click to toggle source

The wire protocol message for this write operation.

@return [ Mongo::Protocol::Query ] Wire protocol message.

@since 2.2.5

# File lib/mongo/operation/write/command/insert.rb, line 57
def message(server)
  opts = options.merge(validating_keys: true)
  Protocol::Query.new(db_name, Database::COMMAND, selector, opts)
end
selector() click to toggle source

The query selector for this insert command operation.

@return [ Hash ] The selector describing this insert operation.

@since 2.0.0

# File lib/mongo/operation/write/command/insert.rb, line 42
def selector
  { insert: coll_name,
    documents: documents,
    ordered: ordered?
  }.tap do |cmd|
    cmd.merge!(writeConcern: write_concern.options) if write_concern
    cmd.merge!(:bypassDocumentValidation => true) if bypass_document_validation
  end
end