Module: Mongo::WriteConcern

Extended by:
WriteConcern
Included in:
WriteConcern
Defined in:
lib/mongo/write_concern.rb,
lib/mongo/write_concern/acknowledged.rb,
lib/mongo/write_concern/normalizable.rb,
lib/mongo/write_concern/unacknowledged.rb

Overview

Base module for all write concern specific behaviour.

Since:

  • 2.0.0

Defined Under Namespace

Modules: Normalizable Classes: Acknowledged, Unacknowledged

Constant Summary

W =

The number of servers write concern.

Since:

  • 2.0.0

:w.freeze
J =

The journal write concern.

Since:

  • 2.0.0

:j.freeze
FSYNC =

The file sync write concern.

Since:

  • 2.0.0

:fsync.freeze
WTIMEOUT =

The wtimeout write concern.

Since:

  • 2.0.0

:wtimeout.freeze
GET_LAST_ERROR =

The GLE command name.

Since:

  • 2.0.0

:getlasterror.freeze
DEFAULT =

The default write concern is to acknowledge on a single server.

Since:

  • 2.0.0

{ }.freeze

Instance Method Summary collapse

Instance Method Details

#get(options) ⇒ Unacknowledged, Acknowledged

Get a write concern mode for the provided options.

Examples:

Get a write concern mode.

Mongo::WriteConcern.get(: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.

Returns:

Raises:

Since:

  • 2.0.0



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mongo/write_concern.rb', line 78

def get(options)
  return options if options.is_a?(Unacknowledged) || options.is_a?(Acknowledged)
  if options
    validate!(options)
    if unacknowledged?(options)
      Unacknowledged.new(options)
    else
      Acknowledged.new(options)
    end
  end
end