Class: Mongo::Operation::Update::BulkResult Private

Inherits:
Result
  • Object
show all
Includes:
Aggregatable
Defined in:
build/ruby-driver-v2.19/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.

Since:

  • 2.0.0

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.

Since:

  • 2.0.0

'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.

Since:

  • 2.0.0

'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_description, #connection_global_id, #replies

Instance Method Summary collapse

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_matchedInteger

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.

Examples:

Get the matched count.

result.n_matched

Returns:

  • (Integer)

    The number of documents matched.

Since:

  • 2.0.0



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'build/ruby-driver-v2.19/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_modifiedInteger

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.

Examples:

Get the modified count.

result.n_modified

Returns:

  • (Integer)

    The number of documents modified.

Since:

  • 2.0.0



92
93
94
95
96
97
98
99
100
101
# File 'build/ruby-driver-v2.19/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_upsertedInteger

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.

Examples:

Get the upserted count.

result.n_upserted

Returns:

  • (Integer)

    The number of documents upserted.

Since:

  • 2.0.0



46
47
48
49
50
51
52
53
54
55
# File 'build/ruby-driver-v2.19/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

#upsertedArray<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.

Examples:

Get upserted documents.

result.upserted

Returns:

  • (Array<BSON::Document>)

    The upserted document info

Since:

  • 2.1.0



111
112
113
114
115
116
117
118
119
# File 'build/ruby-driver-v2.19/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