Class: Mongo::WriteConcern::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/write_concern/base.rb

Overview

Defines common behavior for write concerns.

Since:

  • 2.7.0

Direct Known Subclasses

Acknowledged, Unacknowledged

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

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.

Instantiate a new write concern given the options.

Examples:

Instantiate a new write concern mode.

Mongo::WriteConcern::Acknowledged.new(:w => 1)

Parameters:

  • options (Hash)

    The options to instantiate with.

Options Hash (options):

  • :w (Integer, String)

    The number of servers or the custom mode to acknowledge.

  • :j (true, false)

    Whether to acknowledge a write to the journal.

  • :fsync (true, false)

    Should the write be synced to disc.

  • :wtimeout (Integer)

    The number of milliseconds to wait for acknowledgement before raising an error.

Since:

  • 2.0.0



45
46
47
48
# File 'lib/mongo/write_concern/base.rb', line 45

def initialize(options)
  opts =  Options::Mapper.transform_keys_to_symbols(options)
  @options = Options::Mapper.transform_values_to_strings(opts).freeze
end

Instance Attribute Details

#optionsHash (readonly)

Returns The write concern options.

Returns:

  • (Hash)

    The write concern options.

Since:

  • 2.7.0



24
25
26
# File 'lib/mongo/write_concern/base.rb', line 24

def options
  @options
end

Instance Method Details

#acknowledged?true, false

Is this write concern acknowledged.

Examples:

Whether this write concern object is acknowledged.

write_concern.acknowledged?

Returns:

  • (true, false)

    Whether this write concern is acknowledged.

Since:

  • 2.5.0



58
59
60
# File 'lib/mongo/write_concern/base.rb', line 58

def acknowledged?
  !!get_last_error
end