Class: Mongo::BulkWrite::ResultCombiner Private

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.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.

Combines bulk write results together.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResultCombiner

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.

Create the new result combiner.

Examples:

Create the result combiner.

ResultCombiner.new

Since:

  • 2.1.0



42
43
44
45
# File 'build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.rb', line 42

def initialize
  @results = {}
  @count = 0
end

Instance Attribute Details

#countInteger (readonly)

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.

Returns count The number of documents in the entire batch.

Returns:

  • (Integer)

    count The number of documents in the entire batch.

Since:

  • 2.1.0



29
30
31
# File 'build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.rb', line 29

def count
  @count
end

#resultsHash (readonly)

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.

Returns results The results hash.

Returns:

  • (Hash)

    results The results hash.

Since:

  • 2.1.0



32
33
34
# File 'build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.rb', line 32

def results
  @results
end

Instance Method Details

#combine!(result, count) ⇒ Object

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.

Adds a result to the overall results.

Examples:

Add the result.

combiner.combine!(result, count)

Parameters:

  • result (Operation::Result)

    The result to combine.

  • count (Integer)

    The count of requests in the batch.

Since:

  • 2.1.0



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.rb', line 58

def combine!(result, count)
  # Errors can be communicated by the server in a variety of fields:
  # writeError, writeErrors, writeConcernError, writeConcernErrors.
  # Currently only errors given in writeConcernErrors will cause
  # counts not to be added, because this behavior is covered by the
  # retryable writes tests. It is possible that some or all of the
  # other errors should also be excluded when combining counts and
  # ids, and it is also possible that only a subset of these error
  # fields is actually possible in the context of bulk writes.
  unless result.write_concern_error?
    combine_counts!(result)
    combine_ids!(result)
  end
  combine_errors!(result)
  @count += count
  @acknowledged = result.acknowledged?
end

#resultBulkWrite::Result

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 final result.

Returns:

Since:

  • 2.1.0



83
84
85
# File 'build/ruby-driver-v2.19/lib/mongo/bulk_write/result_combiner.rb', line 83

def result
  BulkWrite::Result.new(results, @acknowledged).validate!
end