Parent

Included Modules

Class/Module Index [+]

Quicksearch

Moped::Protocol::Insert

The Protocol class for inserting documents into a collection.

@example

insert = Insert.new "moped", "people", [{ name: "John" }]

@example Continuing after an error on batch insert

insert = Insert.new "moped", "people",
  [{ unique_field: 1 }, { unique_field: 1 }, { unique_field: 2 }],
  flags: [:continue_on_error]

@example Setting the request id

insert = Insert.new "moped", "people", [{ name: "John" }],
  request_id: 123

Attributes

collection[R]

@return [String, Symbol] the collection this insert targets

database[R]

@return [String, Symbol] the database this insert targets

Public Class Methods

new(database, collection, documents, options = {}) click to toggle source

Create a new insert command. The database and collection arguments are joined together to set the full_collection_name.

@example

Insert.new "moped", "users", [{ name: "John" }],
  flags: [:continue_on_error],
  request_id: 123

@param [String, Symbol] database the database to insert into @param [String, Symbol] collection the collection to insert into @param [Array<Hash>] documents the documents to insert @param [Hash] options additional options @option options [Number] :request_id the command's request id @option options [Array] :flags the flags for insertion. Supported

flags: +:continue_on_error+
# File lib/moped/protocol/insert.rb, line 78
def initialize(database, collection, documents, options = {})
  @database = database
  @collection = collection

  @full_collection_name = "#{database}.#{collection}"
  @documents            = documents
  @request_id           = options[:request_id]
  @flags                = options[:flags]
end

Public Instance Methods

log_inspect() click to toggle source
# File lib/moped/protocol/insert.rb, line 88
def log_inspect
  type = "INSERT"

  "%-12s database=%s collection=%s documents=%s flags=%s" % [type, database, collection, documents.inspect, flags.inspect]
end
op_code() click to toggle source

@return [Number] OP_INSERT operation code (2002)

# File lib/moped/protocol/insert.rb, line 53
def op_code
  2002
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.