Class: Mongo::ServerSelector::Primary

Inherits:
Base
  • Object
show all
Defined in:
lib/mongo/server_selector/primary.rb

Overview

Encapsulates specifications for selecting the primary server given a list

of candidates.

Since:

  • 2.0.0

Constant Summary collapse

SERVER_FORMATTED_NAME =

Name of the this read preference in the server’s format.

Since:

  • 2.5.0

'primary'.freeze

Instance Attribute Summary

Attributes inherited from Base

#hedge, #max_staleness, #options, #tag_sets

Instance Method Summary collapse

Methods inherited from Base

#==, #candidates, #initialize, #inspect, #local_threshold, #local_threshold_with_cluster, #select_server, #server_selection_timeout, #suitable_servers, #try_select_server

Constructor Details

This class inherits a constructor from Mongo::ServerSelector::Base

Instance Method Details

#hedge_allowed?false

Whether the hedge option is allowed to be defined for this server preference.

Returns:

  • (false)

    false

Since:

  • 2.0.0



66
67
68
# File 'lib/mongo/server_selector/primary.rb', line 66

def hedge_allowed?
  false
end

#nameSymbol

Get the name of the server mode type.

Examples:

Get the name of the server mode for this preference.

preference.name

Returns:

Since:

  • 2.0.0



41
42
43
# File 'lib/mongo/server_selector/primary.rb', line 41

def name
  :primary
end

#secondary_ok?false

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.

Whether the secondaryOk bit should be set on wire protocol messages.

I.e. whether the operation can be performed on a secondary server.

Returns:

  • (false)

    false

Since:

  • 2.0.0



50
51
52
# File 'lib/mongo/server_selector/primary.rb', line 50

def secondary_ok?
  false
end

#tags_allowed?false

Whether tag sets are allowed to be defined for this server preference.

Returns:

  • (false)

    false

Since:

  • 2.0.0



59
60
61
# File 'lib/mongo/server_selector/primary.rb', line 59

def tags_allowed?
  false
end

#to_docHash

Convert this server preference definition into a format appropriate

for sending to a MongoDB server (i.e., as a command field).

Returns:

  • (Hash)

    The server preference formatted as a command field value.

Since:

  • 2.5.0



76
77
78
# File 'lib/mongo/server_selector/primary.rb', line 76

def to_doc
  { mode: SERVER_FORMATTED_NAME }
end

#to_mongosHash | nil

Convert this server preference definition into a value appropriate

for sending to a mongos.

This method may return nil if the read preference should not be sent to a mongos.

Returns:

  • (Hash | nil)

    The server preference converted to a mongos command field value.

Since:

  • 2.0.0



90
91
92
# File 'lib/mongo/server_selector/primary.rb', line 90

def to_mongos
  nil
end