Class: Mongo::Server::Description

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/server/description.rb,
build/ruby-driver-v2.19/lib/mongo/server/description/features.rb,
build/ruby-driver-v2.19/lib/mongo/server/description/load_balancer.rb

Overview

Represents a description of the server, populated by the result of the hello command.

Note: Unknown servers do not have wire versions, but for legacy reasons we return 0 for min_wire_version and max_wire_version of any server that does not have them. Presently the driver sometimes constructs commands when the server is unknown, so references to min_wire_version and max_wire_version should not be nil. When driver behavior is changed (jira.mongodb.org/browse/RUBY-1805), this may no longer be necessary.

Since:

  • 2.0.0

Defined Under Namespace

Classes: Features, LoadBalancer

Constant Summary collapse

ARBITER =
Deprecated.

Constant for reading arbiter info from config.

Since:

  • 2.0.0

'arbiterOnly'.freeze
ARBITERS =

Constant for reading arbiters info from config.

Since:

  • 2.0.0

'arbiters'.freeze
HIDDEN =

Constant for reading hidden info from config.

Since:

  • 2.0.0

'hidden'.freeze
HOSTS =

Constant for reading hosts info from config.

Since:

  • 2.0.0

'hosts'.freeze
MESSAGE =
Deprecated.

Constant for the key for the message value.

Since:

  • 2.0.0

'msg'.freeze
MONGOS_MESSAGE =
Deprecated.

Constant for the message that indicates a sharded cluster.

Since:

  • 2.0.0

'isdbgrid'.freeze
REPLICA_SET =
Deprecated.

Constant for determining ghost servers.

Since:

  • 2.0.0

'isreplicaset'.freeze
MAX_BSON_OBJECT_SIZE =

Constant for reading max bson size info from config.

Since:

  • 2.0.0

'maxBsonObjectSize'.freeze
MAX_MESSAGE_BYTES =

Constant for reading max message size info from config.

Since:

  • 2.0.0

'maxMessageSizeBytes'.freeze
MAX_WIRE_VERSION =

Constant for the max wire version.

Since:

  • 2.0.0

'maxWireVersion'.freeze
MIN_WIRE_VERSION =

Constant for min wire version.

Since:

  • 2.0.0

'minWireVersion'.freeze
MAX_WRITE_BATCH_SIZE =

Constant for reading max write batch size.

Since:

  • 2.0.0

'maxWriteBatchSize'.freeze
LAST_WRITE =

Constant for the lastWrite subdocument.

Since:

  • 2.4.0

'lastWrite'.freeze
LAST_WRITE_DATE =

Constant for the lastWriteDate field in the lastWrite subdocument.

Since:

  • 2.4.0

'lastWriteDate'.freeze
ME =

Constant for reading the me field.

Since:

  • 2.1.0

'me'.freeze
DEFAULT_MAX_WRITE_BATCH_SIZE =

Default max write batch size.

Since:

  • 2.0.0

1000.freeze
LEGACY_WIRE_VERSION =
Deprecated.

Will be removed in 3.0.

The legacy wire protocol version.

Since:

  • 2.0.0

0.freeze
PASSIVE =

Constant for reading passive info from config.

Since:

  • 2.0.0

'passive'.freeze
PASSIVES =

Constant for reading the passive server list.

Since:

  • 2.0.0

'passives'.freeze
PRIMARY =
Deprecated.

Constant for reading primary info from config.

Since:

  • 2.0.0

'ismaster'.freeze
PRIMARY_HOST =

Constant for reading primary host field from config.

Since:

  • 2.5.0

'primary'.freeze
SECONDARY =
Deprecated.

Constant for reading secondary info from config.

Since:

  • 2.0.0

'secondary'.freeze
SET_NAME =

Constant for reading replica set name info from config.

Since:

  • 2.0.0

'setName'.freeze
TAGS =

Constant for reading tags info from config.

Since:

  • 2.0.0

'tags'.freeze
ELECTION_ID =

Constant for reading electionId info from config.

Since:

  • 2.1.0

'electionId'.freeze
SET_VERSION =

Constant for reading setVersion info from config.

Since:

  • 2.2.2

'setVersion'.freeze
LOCAL_TIME =

Constant for reading localTime info from config.

Since:

  • 2.1.0

'localTime'.freeze
OPERATION_TIME =

Constant for reading operationTime info from config.

Since:

  • 2.5.0

'operationTime'.freeze
LOGICAL_SESSION_TIMEOUT_MINUTES =

Constant for reading logicalSessionTimeoutMinutes info from config.

Since:

  • 2.5.0

'logicalSessionTimeoutMinutes'.freeze
CONNECTION_ID =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Constant for reading connectionId info from config.

Since:

  • 2.0.0

'connectionId'.freeze
EXCLUDE_FOR_COMPARISON =

Fields to exclude when comparing two descriptions.

Since:

  • 2.0.6

[ LOCAL_TIME,
  LAST_WRITE,
  OPERATION_TIME,
  Operation::CLUSTER_TIME,
  CONNECTION_ID,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, config = {}, average_round_trip_time: nil, load_balancer: false, force_load_balancer: false) ⇒ Description

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 the new server description from the result of the hello command or fabricate a placeholder description for Unknown and LoadBalancer servers.

Examples:

Instantiate the new description.

Description.new(address, { 'isWritablePrimary' => true }, 0.5)

Parameters:

  • address (Address)

    The server address.

  • config (Hash) (defaults to: {})

    The result of the hello command.

  • average_round_trip_time (Float) (defaults to: nil)

    The moving average time (sec) the hello command took to complete.

  • average_round_trip_time (Float) (defaults to: nil)

    The moving average time (sec) the ismaster call took to complete.

  • load_balancer (true | false) (defaults to: false)

    Whether the server is treated as a load balancer.

  • force_load_balancer (true | false) (defaults to: false)

    Whether the server is forced to be a load balancer.

Since:

  • 2.0.0



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 220

def initialize(address, config = {}, average_round_trip_time: nil,
  load_balancer: false, force_load_balancer: false
)
  @address = address
  @config = config
  @load_balancer = !!load_balancer
  @force_load_balancer = !!force_load_balancer
  @features = Features.new(wire_versions, me || @address.to_s)
  @average_round_trip_time = average_round_trip_time
  @last_update_time = Time.now.freeze
  @last_update_monotime = Utils.monotonic_time

  if load_balancer
    # When loadBalanced=true URI option is set, the driver will refuse
    # to work if the server it communicates with does not set serviceId
    # in ismaster/hello response.
    #
    # At the moment we cannot run a proper load balancer setup on evergreen
    #
    # Therefore, when connect=:load_balanced Ruby option is used instead
    # of the loadBalanced=true URI option, if serviceId is not set in
    # ismaster/hello response, the driver fabricates a serviceId and
    # proceeds to treat a server that does not report itself as being
    # behind a load balancer as a server that is behind a load balancer.
    #
    # 5.0+ servers should provide topologyVersion.processId which
    # is specific to the particular process instance. We can use that
    # field as a proxy for serviceId.
    #
    # If the topologyVersion isn't provided for whatever reason, we
    # fabricate a serviceId locally.
    #
    # In either case, a serviceId provided by an actual server behind
    # a load balancer is supposed to be a BSON::ObjectId. The fabricated
    # service ids are strings, to distinguish them from the real ones.
    # In particular processId is also a BSON::ObjectId, but will be
    # mapped to a string for clarity that this is a fake service id.
    #
    # TODO: Remove this when https://jira.mongodb.org/browse/RUBY-2881 is done.
    if ok? && !service_id
      unless force_load_balancer
        raise Error::MissingServiceId, "The server at #{address.seed} did not provide a service id in handshake response"
      end

      fake_service_id = if process_id = topology_version && topology_version['processId']
        "process:#{process_id}"
      else
        "fake:#{rand(2**32-1)+1}"
      end
      @config = @config.merge('serviceId' => fake_service_id)
    end
  end

  if Mongo::Lint.enabled?
    # prepopulate cache instance variables
    hosts
    arbiters
    passives
    topology_version

    freeze
  end
end

Instance Attribute Details

#addressAddress (readonly)

Returns address The server’s address.

Returns:

  • (Address)

    address The server’s address.

Since:

  • 2.0.0



285
286
287
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 285

def address
  @address
end

#average_round_trip_timeFloat (readonly)

Returns The moving average time the hello call took to complete.

Returns:

  • (Float)

    The moving average time the hello call took to complete.

Since:

  • 2.0.0



303
304
305
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 303

def average_round_trip_time
  @average_round_trip_time
end

#configHash (readonly)

Returns The actual result from the hello command.

Returns:

  • (Hash)

    The actual result from the hello command.

Since:

  • 2.0.0



288
289
290
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 288

def config
  @config
end

#last_update_monotimeFloat (readonly)

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.

Time when this server description was created according to monotonic clock.

Returns:

  • (Float)

    Server description creation monotonic time.

See Also:

  • for more detail

Since:

  • 2.0.0



835
836
837
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 835

def last_update_monotime
  @last_update_monotime
end

#last_update_timeTime (readonly)

Note:

This time does not indicate when a successful server check

Time when this server description was created.

completed, because marking a server unknown updates its description and last_update_time. Use Server#last_scan to find out when the server was last successfully checked by its Monitor.

Returns:

  • (Time)

    Server description creation time.

Since:

  • 2.7.0



826
827
828
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 826

def last_update_time
  @last_update_time
end

Instance Method Details

#==(other) ⇒ true, false Also known as: eql?

Check equality of two descriptions.

Examples:

Check description equality.

description == other

Parameters:

  • other (Object)

    The other description.

Returns:

  • (true, false)

    Whether the objects are equal.

Since:

  • 2.0.6



859
860
861
862
863
864
865
866
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 859

def ==(other)
  return false if self.class != other.class
  return false if unknown? || other.unknown?

  (config.keys + other.config.keys).uniq.all? do |k|
    config[k] == other.config[k] || EXCLUDE_FOR_COMPARISON.include?(k)
  end
end

#arbiter?true, false

Returns whether this server is an arbiter, per the SDAM spec.

Examples:

Is the server an arbiter?

description.arbiter?

Returns:

  • (true, false)

    If the server is an arbiter.

Since:

  • 2.0.0



313
314
315
316
317
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 313

def arbiter?
  ok? &&
  config['arbiterOnly'] == true &&
  !!config['setName']
end

#arbitersArray<String>

Get a list of all arbiters in the replica set.

Examples:

Get the arbiters in the replica set.

description.arbiters

Returns:

  • (Array<String>)

    The arbiters in the set.

Since:

  • 2.0.0



327
328
329
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 327

def arbiters
  @arbiters ||= (config[ARBITERS] || []).map { |s| s.downcase }
end

#data_bearing?true, false

Whether this description is from a data-bearing server (standalone, mongos, primary or secondary).

Returns:

  • (true, false)

    Whether the description is from a data-bearing server.

Since:

  • 2.7.0



789
790
791
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 789

def data_bearing?
  mongos? || primary? || secondary? || standalone?
end

#election_idBSON::ObjectId

Get the electionId from the config.

Examples:

Get the electionId.

description.election_id

Returns:

  • (BSON::ObjectId)

    The election id.

Since:

  • 2.1.0



475
476
477
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 475

def election_id
  config[ELECTION_ID]
end

#featuresFeatures

Returns features The features for the server.

Returns:

  • (Features)

    features The features for the server.

Since:

  • 2.0.0



298
299
300
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 298

def features
  @features
end

#ghost?true, false

Whether this server is a ghost, per the SDAM spec.

Examples:

Is the server a ghost?

description.ghost?

Returns:

  • (true, false)

    If the server is a ghost.

Since:

  • 2.0.0



339
340
341
342
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 339

def ghost?
  ok? &&
  config['isreplicaset'] == true
end

#hidden?true, false

Will return true if the server is hidden.

Examples:

Is the server hidden?

description.hidden?

Returns:

  • (true, false)

    If the server is hidden.

Since:

  • 2.0.0



352
353
354
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 352

def hidden?
  ok? && !!config[HIDDEN]
end

#hostsArray<String>

Get a list of all servers in the replica set.

Examples:

Get the servers in the replica set.

description.hosts

Returns:

  • (Array<String>)

    The servers in the set.

Since:

  • 2.0.0



364
365
366
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 364

def hosts
  @hosts ||= (config[HOSTS] || []).map { |s| s.downcase }
end

#inspectString

Inspect the server description.

Examples:

Inspect the server description

description.inspect

Returns:

  • (String)

    The inspection.

Since:

  • 2.0.0



376
377
378
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 376

def inspect
  "#<Mongo::Server:Description:0x#{object_id} config=#{config} average_round_trip_time=#{average_round_trip_time}>"
end

#is_server?(server) ⇒ true, false

Deprecated.

Is this description from the given server.

Examples:

Check if the description is from a given server.

description.is_server?(server)

Returns:

  • (true, false)

    If the description is from the server.

Since:

  • 2.0.6



751
752
753
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 751

def is_server?(server)
  address == server.address
end

#last_write_dateTime

Get the lastWriteDate from the lastWrite subdocument in the config.

Examples:

Get the lastWriteDate value.

description.last_write_date

Returns:

  • (Time)

    The last write date.

Since:

  • 2.4.0



540
541
542
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 540

def last_write_date
  config[LAST_WRITE][LAST_WRITE_DATE] if config[LAST_WRITE]
end

#lists_server?(server) ⇒ true, false

Deprecated.

Is a server included in this description’s list of servers.

Examples:

Check if a server is in the description list of servers.

description.lists_server?(server)

Returns:

  • (true, false)

    If a server is in the description’s list of servers.

Since:

  • 2.0.6



765
766
767
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 765

def lists_server?(server)
  servers.include?(server.address.to_s)
end

#load_balancer?true | false

Returns whether this server is a load balancer.

Returns:

  • (true | false)

    Whether this server is a load balancer.

Since:

  • 2.0.0



293
294
295
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 293

def load_balancer?
  @load_balancer
end

#logical_session_timeoutInteger?

Get the logicalSessionTimeoutMinutes from the config.

Examples:

Get the logicalSessionTimeoutMinutes value in minutes.

description.logical_session_timeout

Returns:

  • (Integer, nil)

    The logical session timeout in minutes.

Since:

  • 2.5.0



552
553
554
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 552

def logical_session_timeout
  config[LOGICAL_SESSION_TIMEOUT_MINUTES] if config[LOGICAL_SESSION_TIMEOUT_MINUTES]
end

#max_bson_object_sizeInteger

Get the max BSON object size for this server version.

Examples:

Get the max BSON object size.

description.max_bson_object_size

Returns:

  • (Integer)

    The maximum object size in bytes.

Since:

  • 2.0.0



388
389
390
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 388

def max_bson_object_size
  config[MAX_BSON_OBJECT_SIZE]
end

#max_message_sizeInteger

Get the max message size for this server version.

Examples:

Get the max message size.

description.max_message_size

Returns:

  • (Integer)

    The maximum message size in bytes.

Since:

  • 2.0.0



400
401
402
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 400

def max_message_size
  config[MAX_MESSAGE_BYTES]
end

#max_wire_versionInteger

Get the maximum wire version. Defaults to zero.

Examples:

Get the max wire version.

description.max_wire_version

Returns:

  • (Integer)

    The max wire version supported.

Since:

  • 2.0.0



424
425
426
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 424

def max_wire_version
  config[MAX_WIRE_VERSION] || 0
end

#max_write_batch_sizeInteger

Get the maximum batch size for writes.

Examples:

Get the max batch size.

description.max_write_batch_size

Returns:

  • (Integer)

    The max batch size.

Since:

  • 2.0.0



412
413
414
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 412

def max_write_batch_size
  config[MAX_WRITE_BATCH_SIZE] || DEFAULT_MAX_WRITE_BATCH_SIZE
end

#meString

Note:

The value in me field may differ from the server description’s address. This can happen, for example, in split horizon configurations. The SDAM spec only requires removing servers whose me does not match their address in some of the situations (e.g. when the server in question is an RS member but not a primary).

Get the me field value.

Returns:

  • (String)

    The me field.

Since:

  • 2.1.0



451
452
453
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 451

def me
  config[ME]
end

#me_mismatch?true, false

Check if there is a mismatch between the address host and the me field.

Examples:

Check if there is a mismatch.

description.me_mismatch?

Returns:

  • (true, false)

    If there is a mismatch between the me field and the address host.

Since:

  • 2.0.6



801
802
803
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 801

def me_mismatch?
  !!(address.to_s.downcase != me.downcase if me)
end

#min_wire_versionInteger

Get the minimum wire version. Defaults to zero.

Examples:

Get the min wire version.

description.min_wire_version

Returns:

  • (Integer)

    The min wire version supported.

Since:

  • 2.0.0



436
437
438
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 436

def min_wire_version
  config[MIN_WIRE_VERSION] || 0
end

#mongos?true, false

Returns whether this server is a mongos, per the SDAM spec.

Examples:

Is the server a mongos?

description.mongos?

Returns:

  • (true, false)

    If the server is a mongos.

Since:

  • 2.0.0



564
565
566
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 564

def mongos?
  ok? && config['msg'] == 'isdbgrid'
end

#ok?Boolean

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.

Returns:

  • (Boolean)

Since:

  • 2.0.0



725
726
727
728
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 725

def ok?
  config[Operation::Result::OK] &&
    config[Operation::Result::OK] == 1 || false
end

#op_timeBSON::Timestamp

opTime in lastWrite subdocument of the hello response.

Returns:

  • (BSON::Timestamp)

    The timestamp.

Since:

  • 2.7.0



810
811
812
813
814
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 810

def op_time
  if config['lastWrite'] && config['lastWrite']['opTime']
    config['lastWrite']['opTime']['ts']
  end
end

#other?true, false

Returns whether the server is an other, per the SDAM spec.

Examples:

Is the description of type other.

description.other?

Returns:

  • (true, false)

    If the description is other.

Since:

  • 2.0.0



576
577
578
579
580
581
582
583
584
585
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 576

def other?
  # The SDAM spec is slightly confusing on what "other" means,
  # but it's referred to it as "RSOther" which means a non-RS member
  # cannot be "other".
  ok? &&
  !!config['setName'] && (
    config['hidden'] == true ||
    !primary? && !secondary? && !arbiter?
  )
end

#passive?true, false

Will return true if the server is passive.

Examples:

Is the server passive?

description.passive?

Returns:

  • (true, false)

    If the server is passive.

Since:

  • 2.0.0



595
596
597
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 595

def passive?
  ok? && !!config[PASSIVE]
end

#passivesArray<String>

Get a list of the passive servers in the cluster.

Examples:

Get the passives.

description.passives

Returns:

  • (Array<String>)

    The list of passives.

Since:

  • 2.0.0



607
608
609
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 607

def passives
  @passives ||= (config[PASSIVES] || []).map { |s| s.downcase }
end

#primary?true, false

Returns whether this server is a primary, per the SDAM spec.

Examples:

Is the server a primary?

description.primary?

Returns:

  • (true, false)

    If the server is a primary.

Since:

  • 2.0.0



631
632
633
634
635
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 631

def primary?
  ok? &&
    (config['ismaster'] == true || config['isWritablePrimary'] == true ) &&
  !!config['setName']
end

#primary_hostString | nil

Get the address of the primary host.

Examples:

Get the address of the primary.

description.primary_host

Returns:

  • (String | nil)

    The address of the primary.

Since:

  • 2.6.0



619
620
621
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 619

def primary_host
  config[PRIMARY_HOST] && config[PRIMARY_HOST].downcase
end

#replica_set_member?true, false

Does this description correspond to a replica set member.

Examples:

Check if the description is from a replica set member.

description.replica_set_member?

Returns:

  • (true, false)

    If the description is from a replica set member.

Since:

  • 2.0.6



778
779
780
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 778

def replica_set_member?
  ok? && !(standalone? || mongos?)
end

#replica_set_nameString?

Get the name of the replica set the server belongs to, returns nil if none.

Examples:

Get the replica set name.

description.replica_set_name

Returns:

  • (String, nil)

    The name of the replica set.

Since:

  • 2.0.0



646
647
648
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 646

def replica_set_name
  config[SET_NAME]
end

#secondary?true, false

Returns whether this server is a secondary, per the SDAM spec.

Examples:

Is the server a secondary?

description.secondary?

Returns:

  • (true, false)

    If the server is a secondary.

Since:

  • 2.0.0



670
671
672
673
674
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 670

def secondary?
  ok? &&
  config['secondary'] == true &&
  !!config['setName']
end

#server_connection_idObject

Since:

  • 2.0.0



838
839
840
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 838

def server_connection_id
  config['connectionId']
end

#server_typeSymbol

Returns the server type as a symbol.

Examples:

Get the server type.

description.server_type

Returns:

  • (Symbol)

    The server type.

Since:

  • 2.4.0



684
685
686
687
688
689
690
691
692
693
694
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 684

def server_type
  return :load_balancer if load_balancer?
  return :arbiter if arbiter?
  return :ghost if ghost?
  return :sharded if mongos?
  return :primary if primary?
  return :secondary if secondary?
  return :standalone if standalone?
  return :other if other?
  :unknown
end

#server_version_gte?(version) ⇒ Boolean

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.

Returns:

  • (Boolean)

Since:

  • 2.0.0



870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 870

def server_version_gte?(version)
  required_wv = case version
    when '7.0'
      21
    when '6.0'
      17
    when '5.2'
      15
    when '5.1'
      14
    when '5.0'
      12
    when '4.4'
      9
    when '4.2'
      8
    when '4.0'
      7
    when '3.6'
      6
    when '3.4'
      5
    when '3.2'
      4
    when '3.0'
      3
    when '2.6'
      2
    else
      raise ArgumentError, "Bogus required version #{version}"
    end

  if load_balancer?
    # If we are talking to a load balancer, there is no monitoring
    # and we don't know what server is behind the load balancer.
    # Assume everything is supported.
    # TODO remove this when RUBY-2220 is implemented.
    return true
  end

  required_wv >= min_wire_version && required_wv <= max_wire_version
end

#serversArray<String>

Get a list of all servers known to the cluster.

Examples:

Get all servers.

description.servers

Returns:

  • (Array<String>)

    The list of all servers.

Since:

  • 2.0.0



658
659
660
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 658

def servers
  hosts + arbiters + passives
end

#service_idnil | Object

Returns The service id, if any.

Returns:

  • (nil | Object)

    The service id, if any.

Since:

  • 2.0.0



845
846
847
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 845

def service_id
  config['serviceId']
end

#set_versionInteger

Get the setVersion from the config.

Examples:

Get the setVersion.

description.set_version

Returns:

  • (Integer)

    The set version.

Since:

  • 2.2.2



487
488
489
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 487

def set_version
  config[SET_VERSION]
end

#standalone?true, false

Returns whether this server is a standalone, per the SDAM spec.

Examples:

Is the server standalone?

description.standalone?

Returns:

  • (true, false)

    If the server is standalone.

Since:

  • 2.0.0



704
705
706
707
708
709
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 704

def standalone?
  ok? &&
  config['msg'] != 'isdbgrid' &&
  config['setName'].nil? &&
  config['isreplicaset'] != true
end

#tagsHash

Get the tags configured for the server.

Examples:

Get the tags.

description.tags

Returns:

  • (Hash)

    The tags of the server.

Since:

  • 2.0.0



463
464
465
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 463

def tags
  config[TAGS] || {}
end

#topology_versionTopologyVersion | nil

Returns The topology version.

Returns:

Since:

  • 2.0.0



492
493
494
495
496
497
498
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 492

def topology_version
  unless defined?(@topology_version)
    @topology_version = config['topologyVersion'] &&
      TopologyVersion.new(config['topologyVersion'])
  end
  @topology_version
end

#topology_version_gt?(other_desc) ⇒ true | 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.

Returns whether topology version in this description is potentially newer than or equal to topology version in another description.

Parameters:

Returns:

  • (true | false)

    Whether topology version in this description is potentially newer or equal.

Since:

  • 2.0.0



508
509
510
511
512
513
514
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 508

def topology_version_gt?(other_desc)
  if topology_version.nil? || other_desc.topology_version.nil?
    true
  else
    topology_version.gt?(other_desc.topology_version)
  end
end

#topology_version_gte?(other_desc) ⇒ true | 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.

Returns whether topology version in this description is potentially newer than topology version in another description.

Parameters:

Returns:

  • (true | false)

    Whether topology version in this description is potentially newer.

Since:

  • 2.0.0



524
525
526
527
528
529
530
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 524

def topology_version_gte?(other_desc)
  if topology_version.nil? || other_desc.topology_version.nil?
    true
  else
    topology_version.gte?(other_desc.topology_version)
  end
end

#unknown?true, false

Returns whether this server is an unknown, per the SDAM spec.

Examples:

Is the server description unknown?

description.unknown?

Returns:

  • (true, false)

    If the server description is unknown.

Since:

  • 2.0.0



719
720
721
722
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 719

def unknown?
  return false if load_balancer?
  config.empty? || config.keys == %w(topologyVersion) || !ok?
end

#wire_versionsRange

Get the range of supported wire versions for the server.

Examples:

Get the wire version range.

description.wire_versions

Returns:

  • (Range)

    The wire version range.

Since:

  • 2.0.0



738
739
740
# File 'build/ruby-driver-v2.19/lib/mongo/server/description.rb', line 738

def wire_versions
  min_wire_version..max_wire_version
end