class 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
@return [String, Symbol] the collection this insert targets
@return [String, Symbol] the database this insert targets
Public Class Methods
Source
# 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
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+
Public Instance Methods
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
Source
# File lib/moped/protocol/insert.rb, line 53 def op_code 2002 end
@return [Number] OP_INSERT operation code (2002)