Class: Mongo::Operation::Update::BulkResult Private
- Includes:
- Aggregatable
- Defined in:
- lib/mongo/operation/update/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 udpate when sent as part of a bulk write.
Constant Summary collapse
- MODIFIED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The number of modified docs field in the result.
'nModified'.freeze
- UPSERTED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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
#connection, #connection_description, #connection_global_id, #context, #replies
Instance Method Summary collapse
-
#n_matched ⇒ Integer
private
Gets the number of documents matched.
-
#n_modified ⇒ Integer
private
Gets the number of documents modified.
-
#n_upserted ⇒ Integer
private
Gets the number of documents upserted.
-
#upserted ⇒ Array<BSON::Document>
private
Get the upserted documents.
Methods inherited from Result
#acknowledged?, #cluster_time, #cursor_id, #documents, #each, #error, #has_cursor_id?, #initialize, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #successful?, #topology_version, #validate!, #write_concern_error?, #written_count
Constructor Details
This class inherits a constructor from Mongo::Operation::Result
Instance Method Details
#n_matched ⇒ 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 matched.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 65 def n_matched return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) reply.documents.first[N] - n_upserted else if reply.documents.first[N] n += reply.documents.first[N] else n end end end end |
#n_modified ⇒ 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 modified. Not that in a mixed sharded cluster a call to update could return nModified (>= 2.6) or not (<= 2.4). If any call does not return nModified we can’t report a valid final count so set the field to nil.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 92 def n_modified return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if n && reply.documents.first[MODIFIED] n += reply.documents.first[MODIFIED] else 0 end end end |
#n_upserted ⇒ 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 upserted.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 46 def n_upserted return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) n += reply.documents.first[UPSERTED].size else n end end end |
#upserted ⇒ Array<BSON::Document>
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 upserted documents.
111 112 113 114 115 116 117 118 119 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 111 def upserted return [] unless acknowledged? @replies.reduce([]) do |ids, reply| if upserted_ids = reply.documents.first[UPSERTED] ids += upserted_ids end ids end end |