BulkResult — Documentation by YARD 0.9.37 (original) (raw)

Class: Mongo::Operation::Insert::BulkResult

Inherits:

Result

Includes:

Aggregatable

Defined in:

lib/mongo/operation/insert/bulk_result.rb

Overview

Defines custom behavior of results for an insert when sent as part of a bulk write.

Constant Summary

Constants inherited from Result

Result::CURSOR, Result::CURSOR_ID, Result::FIRST_BATCH, Result::N, Result::NAMESPACE, Result::NEXT_BATCH, Result::OK, Result::RESULT

Instance Attribute Summary collapse

Attributes inherited from Result

#connection, #connection_description, #connection_global_id, #context, #replies

Instance Method Summarycollapse

Methods inherited from Result

#acknowledged?, #cluster_time, #cursor_id, #documents, #each, #error, #has_cursor_id?, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #successful?, #topology_version, #validate!, #write_concern_error?, #written_count

Constructor Details

#initialize(replies, connection_description, connection_global_id, ids) ⇒ BulkResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new result.

| 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | # File 'lib/mongo/operation/insert/bulk_result.rb', line 51 def initialize(, connection_description, connection_global_id, ids) @replies = [*] if @connection_description = connection_description @connection_global_id = connection_global_id if && .first && (doc = .first.documents.first) if errors = doc['writeErrors'] bad_indices = {} errors.map do |error| bad_indices[error['index']] = true end @inserted_ids = [] ids.each_with_index do | id, index| if bad_indices[index].nil? @inserted_ids << id end end elsif acknowledged? && successful? @inserted_ids = ids else @inserted_ids = [] end else @inserted_ids = ids end end | | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Instance Attribute Details

#inserted_ids ⇒ Object

Get the ids of the inserted documents.

33 34 35 # File 'lib/mongo/operation/insert/bulk_result.rb', line 33 def inserted_ids @inserted_ids end

Instance Method Details

#inserted_id ⇒ Object

Gets the id of the document inserted.

110 111 112 # File 'lib/mongo/operation/insert/bulk_result.rb', line 110 def inserted_id inserted_ids.first end

#n_inserted ⇒ Integer

Gets the number of documents inserted.

97 98 99 # File 'lib/mongo/operation/insert/bulk_result.rb', line 97 def n_inserted written_count end