Method: Mongo::Error::Parser#initialize

Defined in:
lib/mongo/error/parser.rb

#initialize(document, replies = nil, options = nil) ⇒ Parser

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 parser with the returned document.

In legacy mode, the code and codeName fields of the document are not examined because the status (ok: 1) is not part of the document and there is no way to distinguish successful from failed responses using the document itself, and a successful response may legitimately have { code: 123, codeName: ‘foo’ } as the contents of a user-inserted document. The legacy server versions do not fill out code nor codeName thus not reading them does not lose information.

Examples:

Create the new parser.

Parser.new({ 'errmsg' => 'failed' })

Parameters:

  • document (BSON::Document)

    The returned document.

  • replies (Array<Protocol::Message>) (defaults to: nil)

    The message replies.

  • options (Hash) (defaults to: nil)

    The options.

Options Hash (options):

  • :legacy (true | false)

    Whether document and replies are from a legacy (pre-3.2) response

Since:

  • 2.0.0



122
123
124
125
126
127
128
129
130
131
# File 'lib/mongo/error/parser.rb', line 122

def initialize(document, replies = nil, options = nil)
  @document = document || {}
  @replies = replies
  @options = if options
    options.dup
  else
    {}
  end.freeze
  parse!
end