The MongoDB\Driver\TopologyDescription class

- « MongoDB\Driver\ServerDescription::getType

- MongoDB\Driver\TopologyDescription::getServers »

- PHP Manual
- MongoDB\Driver
- The MongoDB\Driver\TopologyDescription class

# The MongoDB\Driver\TopologyDescription class

(mongodb >=1.13.0)

## Introduction

The MongoDB\Driver\TopologyDescription class is a value object that represents a topology to which the driver is connected. Instances of this class are returned by MongoDB\Driver\Monitoring\TopologyChangedEvent methods.

## Class synopsis

final class MongoDB\Driver\TopologyDescription {
/* Constants */
const string TYPE_UNKNOWN = "Unknown";
const string TYPE_SINGLE = "Single";
const string TYPE_SHARDED = "Sharded";
const string TYPE_REPLICA_SET_NO_PRIMARY = "ReplicaSetNoPrimary";
const string TYPE_REPLICA_SET_WITH_PRIMARY = "ReplicaSetWithPrimary";
const string TYPE_LOAD_BALANCED = "LoadBalanced";
/* Methods */
final public getServers(): array
final public getType(): string
final public hasReadableServer(?MongoDB\Driver\ReadPreference `$readPreference` = `null`): bool
final public hasWritableServer(): bool
}

## Predefined Constants

`MongoDB\Driver\TopologyDescription::TYPE_UNKNOWN`

  Unknown topology type, returned by MongoDB\Driver\TopologyDescription::getType().

`MongoDB\Driver\TopologyDescription::TYPE_SINGLE`

  Single server (i.e. direct connection), returned by MongoDB\Driver\TopologyDescription::getType().

`MongoDB\Driver\TopologyDescription::TYPE_SHARDED`

  Sharded cluster, returned by MongoDB\Driver\TopologyDescription::getType().

`MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_NO_PRIMARY`

  Replica set with no primary server, returned by MongoDB\Driver\TopologyDescription::getType().

`MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_WITH_PRIMARY`

  Replica set with a primary server, returned by MongoDB\Driver\TopologyDescription::getType().

`MongoDB\Driver\TopologyDescription::TYPE_LOAD_BALANCED`

  Load balanced topology, returned by MongoDB\Driver\TopologyDescription::getType().

## Table of Contents

- MongoDB\Driver\TopologyDescription::getServers — Returns the servers in the topology
- MongoDB\Driver\TopologyDescription::getType — Returns a string denoting the type of this topology
- MongoDB\Driver\TopologyDescription::hasReadableServer — Returns whether the topology has a readable server
- MongoDB\Driver\TopologyDescription::hasWritableServer — Returns whether the topology has a writable server