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 update 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'- 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'
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.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 64 def n_matched return 0 unless acknowledged? @replies.reduce(0) do |n, reply| if upsert?(reply) reply.documents.first[N] - n_upserted elsif reply.documents.first[N] n + reply.documents.first[N] else n 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.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 86 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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 44 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.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mongo/operation/update/bulk_result.rb', line 106 def upserted return [] unless acknowledged? @replies.reduce([]) do |ids, reply| if upserted_ids = reply.documents.first[UPSERTED] ids += upserted_ids end ids end end |