Module: Mongo::Cluster::Topology

Extended by:
Topology
Included in:
Topology
Defined in:
lib/mongo/cluster/topology.rb,
lib/mongo/cluster/topology/single.rb,
lib/mongo/cluster/topology/sharded.rb,
lib/mongo/cluster/topology/unknown.rb,
lib/mongo/cluster/topology/replica_set.rb

Overview

Defines behavior for getting servers.

Topologies are associated with their clusters - for example, a ReplicaSet topology contains the replica set name. A topology object therefore cannot be used with multiple cluster objects.

At the same time, topology objects do not know anything about specific servers in a cluster, despite what their constructor may suggest. Which means, in particular, that topology change events require the application to maintain cluster references on its own if it wants to track server changes within a replica set.

Since:

  • 2.0.0

Defined Under Namespace

Classes: ReplicaSet, Sharded, Single, Unknown

Constant Summary collapse

OPTIONS =

The various topologies for server selection.

Since:

  • 2.0.0

{
  replica_set: ReplicaSet,
  sharded: Sharded,
  direct: Single
}.freeze

Instance Method Summary collapse

Instance Method Details

#initial(seeds, monitoring, options) ⇒ ReplicaSet, ...

Get the initial cluster topology for the provided options.

Examples:

Get the initial cluster topology.

Topology.initial(topology: :replica_set)

Parameters:

  • seeds (Array<String>)

    The addresses of the configured servers.

  • monitoring (Monitoring)

    The monitoring.

  • options (Hash)

    The cluster options.

Returns:

Since:

  • 2.0.0



60
61
62
63
64
65
66
67
68
# File 'lib/mongo/cluster/topology.rb', line 60

def initial(seeds, monitoring, options)
  if options.has_key?(:connect)
    OPTIONS.fetch(options[:connect].to_sym).new(options, monitoring, seeds)
  elsif options.has_key?(:replica_set)
    ReplicaSet.new(options, monitoring, seeds)
  else
    Unknown.new(options, monitoring, seeds)
  end
end