Class: Mongo::Operation::Insert::BulkResult Private
- Includes:
- Aggregatable
- Defined in:
- lib/mongo/operation/insert/bulk_result.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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
-
#inserted_ids ⇒ Object
readonly
private
Get the ids of the inserted documents.
Attributes inherited from Result
#connection_description, #replies
Instance Method Summary collapse
-
#initialize(replies, connection_description, ids) ⇒ BulkResult
constructor
private
Initialize a new result.
-
#inserted_id ⇒ Object
private
Gets the id of the document inserted.
-
#n_inserted ⇒ Integer
private
Gets the number of documents inserted.
Methods inherited from Result
#acknowledged?, #cluster_time, #cursor_id, #documents, #each, #error, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #returned_count, #successful?, #topology_version, #validate!, #write_concern_error?, #written_count
Constructor Details
#initialize(replies, connection_description, 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.
42 43 44 45 46 47 48 49 50 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 |
# File 'lib/mongo/operation/insert/bulk_result.rb', line 42 def initialize(replies, connection_description, ids) @replies = [*replies] if replies @connection_description = connection_description if replies && replies.first && (doc = replies.first.documents.first) if errors = doc['writeErrors'] # some documents were potentially inserted 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 # I don't know if acknowledged? check here is necessary, # as best as I can tell it doesn't hurt elsif acknowledged? && successful? # We have a reply and the reply is successful and the # reply has no writeErrors - everything got inserted @inserted_ids = ids else # We have a reply and the reply is not successful and # it has no writeErrors - nothing got inserted. # If something got inserted the reply will be not successful # but will have writeErrors @inserted_ids = [] end else # I don't think we should ever get here but who knows, # make this behave as old drivers did @inserted_ids = ids end end |
Instance Attribute Details
#inserted_ids ⇒ Object (readonly)
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.
Get the ids of the inserted documents.
28 29 30 |
# File 'lib/mongo/operation/insert/bulk_result.rb', line 28 def inserted_ids @inserted_ids end |
Instance Method Details
#inserted_id ⇒ Object
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.
Gets the id of the document inserted.
98 99 100 |
# File 'lib/mongo/operation/insert/bulk_result.rb', line 98 def inserted_id inserted_ids.first end |
#n_inserted ⇒ Integer
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.
Gets the number of documents inserted.
86 87 88 |
# File 'lib/mongo/operation/insert/bulk_result.rb', line 86 def n_inserted written_count end |