Class: Mongo::ServerSelector::PrimaryPreferred
- Inherits:
-
Object
- Object
- Mongo::ServerSelector::PrimaryPreferred
- Includes:
- Selectable
- Defined in:
- lib/mongo/server_selector/primary_preferred.rb
Overview
Encapsulates specifications for selecting servers, with the
primary preferred, given a list of candidates.
Constant Summary collapse
- SERVER_FORMATTED_NAME =
Name of the this read preference in the server’s format.
'primaryPreferred'.freeze
Instance Attribute Summary
Attributes included from Selectable
#max_staleness, #options, #tag_sets
Instance Method Summary collapse
-
#name ⇒ Symbol
Get the name of the server mode type.
-
#slave_ok? ⇒ true
Whether the slaveOk bit should be set on wire protocol messages.
-
#tags_allowed? ⇒ true
Whether tag sets are allowed to be defined for this server preference.
-
#to_mongos ⇒ Hash
(also: #to_doc)
Convert this server preference definition into a format appropriate for a mongos server.
Methods included from Selectable
#==, #candidates, #initialize, #inspect, #local_threshold, #select_server, #server_selection_timeout
Instance Method Details
#name ⇒ Symbol
Get the name of the server mode type.
39 40 41 |
# File 'lib/mongo/server_selector/primary_preferred.rb', line 39 def name :primary_preferred end |
#slave_ok? ⇒ true
Whether the slaveOk bit should be set on wire protocol messages.
I.e. whether the operation can be performed on a secondary server.
49 50 51 |
# File 'lib/mongo/server_selector/primary_preferred.rb', line 49 def slave_ok? true end |
#tags_allowed? ⇒ true
Whether tag sets are allowed to be defined for this server preference.
58 59 60 |
# File 'lib/mongo/server_selector/primary_preferred.rb', line 58 def true end |
#to_mongos ⇒ Hash Also known as: to_doc
Convert this server preference definition into a format appropriate
for a mongos server.
73 74 75 76 77 78 |
# File 'lib/mongo/server_selector/primary_preferred.rb', line 73 def to_mongos @doc ||= (preference = { :mode => SERVER_FORMATTED_NAME } preference.merge!({ :tags => tag_sets }) unless tag_sets.empty? preference.merge!({ maxStalenessSeconds: max_staleness }) if max_staleness preference) end |