Class: Mongo::ServerSelector::Secondary

Inherits:
Object
  • Object
show all
Includes:
Selectable
Defined in:
lib/mongo/server_selector/secondary.rb

Overview

Encapsulates specifications for selecting secondary servers given a list

of candidates.

Since:

  • 2.0.0

Instance Attribute Summary

Attributes included from Selectable

#max_staleness, #options, #tag_sets

Instance Method Summary collapse

Methods included from Selectable

#==, #candidates, #initialize, #inspect, #local_threshold, #select_server, #server_selection_timeout

Instance Method Details

#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



34
35
36
# File 'lib/mongo/server_selector/secondary.rb', line 34

def name
  :secondary
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.

Returns:

  • (true)

    true

Since:

  • 2.0.0



44
45
46
# File 'lib/mongo/server_selector/secondary.rb', line 44

def slave_ok?
  true
end

#tags_allowed?true

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

Returns:

  • (true)

    true

Since:

  • 2.0.0



53
54
55
# File 'lib/mongo/server_selector/secondary.rb', line 53

def tags_allowed?
  true
end

#to_mongosHash

Convert this server preference definition into a format appropriate

for a mongos server.

Examples:

Convert this server preference definition into a format

for mongos.
preference = Mongo::ServerSelector::Secondary.new
preference.to_mongos

Returns:

  • (Hash)

    The server preference formatted for a mongos server.

Since:

  • 2.0.0



68
69
70
71
72
73
# File 'lib/mongo/server_selector/secondary.rb', line 68

def to_mongos
  preference = { :mode => 'secondary' }
  preference.merge!({ :tags => tag_sets }) unless tag_sets.empty?
  preference.merge!({ maxStalenessSeconds: max_staleness }) if max_staleness
  preference
end