Class: Mongo::Operation::Write::Bulk::Insert::LegacyResult
- Includes:
- LegacyMergable
- Defined in:
- lib/mongo/operation/write/bulk/insert/result.rb
Overview
Defines custom behaviour of results when inserting. For server versions < 2.5.5 (that don’t use write commands).
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
Get the ids of the inserted documents.
Attributes inherited from Result
Instance Method Summary collapse
-
#initialize(replies, ids) ⇒ LegacyResult
constructor
Initialize a new result.
-
#inserted_id ⇒ Object
Gets the id of the document inserted.
-
#n_inserted ⇒ Integer
Gets the number of documents inserted.
Methods included from LegacyMergable
#aggregate_write_concern_errors, #aggregate_write_errors
Methods inherited from Result
#acknowledged?, #cursor_id, #documents, #each, #inspect, #multiple?, #namespace, #ok?, #reply, #returned_count, #successful?, #validate!, #written_count
Constructor Details
#initialize(replies, ids) ⇒ LegacyResult
Initialize a new result.
92 93 94 95 |
# File 'lib/mongo/operation/write/bulk/insert/result.rb', line 92 def initialize(replies, ids) @replies = replies.is_a?(Protocol::Reply) ? [ replies ] : replies @inserted_ids = ids end |
Instance Attribute Details
#inserted_ids ⇒ Object (readonly)
Get the ids of the inserted documents.
81 82 83 |
# File 'lib/mongo/operation/write/bulk/insert/result.rb', line 81 def inserted_ids @inserted_ids end |
Instance Method Details
#inserted_id ⇒ Object
Gets the id of the document inserted.
121 122 123 |
# File 'lib/mongo/operation/write/bulk/insert/result.rb', line 121 def inserted_id inserted_ids.first end |
#n_inserted ⇒ Integer
Gets the number of documents inserted.
105 106 107 108 109 110 111 |
# File 'lib/mongo/operation/write/bulk/insert/result.rb', line 105 def n_inserted return 0 unless acknowledged? @replies.reduce(0) do |n, reply| n += 1 unless reply_write_errors?(reply) n end end |