Class: Mongo::Operation::Write::Bulk::Update::Result
- Includes:
- Mergable
- Defined in:
- lib/mongo/operation/write/bulk/update/result.rb
Overview
Defines custom behaviour of results when updating.
Constant Summary collapse
- MODIFIED =
The number of modified docs field in the result.
'nModified'.freeze
- UPSERTED =
The upserted docs field in the result.
'upserted'.freeze
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
Attributes inherited from Result
Instance Method Summary collapse
-
#n_matched ⇒ Integer
Gets the number of documents matched.
-
#n_modified ⇒ Integer
Gets the number of documents modified.
-
#n_upserted ⇒ Integer
Gets the number of documents upserted.
-
#upserted ⇒ Array<BSON::Document>
Get the upserted documents.
Methods included from Mergable
#aggregate_write_concern_errors, #aggregate_write_errors
Methods inherited from Result
#acknowledged?, #cursor_id, #documents, #each, #initialize, #inspect, #multiple?, #namespace, #ok?, #reply, #returned_count, #successful?, #validate!, #written_count
Constructor Details
This class inherits a constructor from Mongo::Operation::Result
Instance Method Details
#n_matched ⇒ Integer
Gets the number of documents matched.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mongo/operation/write/bulk/update/result.rb', line 64 def n_matched return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) n += 0 else n += reply.documents.first[N] end end end |
#n_modified ⇒ Integer
Gets the number of documents modified.
83 84 85 86 87 88 |
# File 'lib/mongo/operation/write/bulk/update/result.rb', line 83 def n_modified return 0 unless acknowledged? @replies.reduce(0) do |n, reply| n += reply.documents.first[MODIFIED] || 0 end end |
#n_upserted ⇒ Integer
Gets the number of documents upserted.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongo/operation/write/bulk/update/result.rb', line 45 def n_upserted return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) n += 1 else n += 0 end end end |
#upserted ⇒ Array<BSON::Document>
Get the upserted documents.
98 99 100 |
# File 'lib/mongo/operation/write/bulk/update/result.rb', line 98 def upserted reply.documents.first[UPSERTED] || [] end |