Exception: Mongo::Error::BulkWriteError

Inherits:
Mongo::Error
  • Object
show all
Defined in:
lib/mongo/error/bulk_write_error.rb

Overview

Exception raised if there are write errors upon executing the bulk operation.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Mongo::Error

BAD_VALUE, CODE, CURSOR_NOT_FOUND, ERR, ERRMSG, ERROR, TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_ERROR, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL, WRITE_CONCERN_ERROR, WRITE_CONCERN_ERRORS, WRITE_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Mongo::Error

#change_stream_resumable?, #label?, #labels

Constructor Details

#initialize(result) ⇒ BulkWriteError

Instantiate the new exception.

Examples:

Instantiate the exception.

Mongo::Error::BulkWriteError.new(response)

Parameters:

  • result (Hash)

    A processed response from the server reporting results of the operation.

Since:

  • 2.0.0



36
37
38
# File 'lib/mongo/error/bulk_write_error.rb', line 36

def initialize(result)
  @result = result
end

Instance Attribute Details

#resultBSON::Document (readonly)

Returns result The error result.

Returns:

  • (BSON::Document)

    result The error result.

Since:

  • 2.0.0



25
26
27
# File 'lib/mongo/error/bulk_write_error.rb', line 25

def result
  @result
end

Instance Method Details

#to_sObject

Since:

  • 2.0.0



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mongo/error/bulk_write_error.rb', line 40

def to_s
  messages = if errors = result['writeErrors']
    frag = ': ' + errors[0..10].map do |error|
      "#{error['errmsg']} (#{error['code']})"
    end.join(', ')
    if errors.length > 10
      frag += '...'
    else
      frag
    end
  else
    ''
  end
  self.class.name + messages
end