final class Server (View source)

Constants

TYPE_UNKNOWN

TYPE_STANDALONE

TYPE_MONGOS

TYPE_POSSIBLE_PRIMARY

TYPE_RS_PRIMARY

TYPE_RS_SECONDARY

TYPE_RS_ARBITER

TYPE_RS_OTHER

TYPE_RS_GHOST

TYPE_LOAD_BALANCER Since: 1.11.0

Methods

__wakeup()

No description

executeBulkWrite(string $namespace, BulkWrite $bulkWrite, array|null $options = null)

Execute one or more write operations on this server

executeBulkWriteCommand(BulkWriteCommand $bulkWriteCommand, array|null $options = null)

Execute write operations on this server using the bulkWrite command

executeCommand(string $db, Command $command, array|null $options = null)

Execute a database command on this server

executeReadCommand(string $db, Command $command, array|null $options = null)

Execute a database command that reads on this server

executeReadWriteCommand(string $db, Command $command, array|null $options = null)

Execute a database command that reads and writes on this server

executeWriteCommand(string $db, Command $command, array|null $options = null)

Execute a database command that writes on this server

executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null)

Execute a database query on this server

string
getHost()

Returns the hostname of this server

array
getInfo()

Returns an array of information about this server

int
getLatency()

Returns the latency of this server

int
getPort()

Returns the port on which this server is listening

array
getTags()

Returns an array of tags describing this server in a replica set

int
getType()

Returns an integer denoting the type of this server

bool
isArbiter()

Checks if this server is an arbiter member of a replica set

bool
isHidden()

Checks if this server is a hidden member of a replica set

bool
isPassive()

Checks if this server is a passive member of a replica set

bool
isPrimary()

Checks if this server is a primary member of a replica set

bool
isSecondary()

Checks if this server is a secondary member of a replica set

Details

final __wakeup()

No description

final WriteResult executeBulkWrite(string $namespace, BulkWrite $bulkWrite, array|null $options = null)

Since: 1.0.0

Execute one or more write operations on this server

Parameters

string $namespace

A fully qualified namespace (e.g. "databaseName.collectionName").

BulkWrite $bulkWrite

The MongoDB\Driver\BulkWrite to execute.

array|null $options

options Option Type Description session MongoDB\Driver\Session A session to associate with the operation. writeConcern MongoDB\Driver\WriteConcern A write concern to apply to the operation.

Return Value

WriteResult

Returns MongoDB\Driver\WriteResult on success.

Exceptions

BulkWriteException
InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final BulkWriteCommandResult executeBulkWriteCommand(BulkWriteCommand $bulkWriteCommand, array|null $options = null)

Since: 2.1.0

Execute write operations on this server using the bulkWrite command

Parameters

BulkWriteCommand $bulkWriteCommand

The write(s) to execute.

array|null $options

options Option Type Description session MongoDB\Driver\Session A session to associate with the operation. writeConcern MongoDB\Driver\WriteConcern A write concern to apply to the operation.

Return Value

BulkWriteCommandResult

Returns MongoDB\Driver\BulkWriteCommandResult on success.

Exceptions

BulkWriteCommandException
InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final CursorInterface executeCommand(string $db, Command $command, array|null $options = null)

Since: 1.0.0

Execute a database command on this server

Parameters

string $db

The name of the database on which to execute the command.

Command $command

The MongoDB\Driver\Command to execute.

array|null $options

Optionally, a MongoDB\Driver\ReadPreference to select the server for this operation. If none is given, the read preference from the MongoDB Connection URI will be used.

Return Value

CursorInterface

Returns MongoDB\Driver\Cursor on success.

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final CursorInterface executeReadCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

Execute a database command that reads on this server

Parameters

string $db

The name of the database on which to execute the command.

Command $command

The command to execute.

array|null $options

options Option Type Description readConcern MongoDB\Driver\ReadConcern A read concern to apply to the operation. This option is available in MongoDB 3.2+ and will result in an exception at execution time if specified for an older server version. readPreference MongoDB\Driver\ReadPreference A read preference to use for selecting a server for the operation. session MongoDB\Driver\Session A session to associate with the operation. If you are using a "session" which has a transaction in progress, you cannot specify a "readConcern" or "writeConcern" option. This will result in an MongoDB\Driver\Exception\InvalidArgumentException being thrown. Instead, you should set these two options when you create the transaction with MongoDB\Driver\Session::startTransaction.

Return Value

CursorInterface

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final CursorInterface executeReadWriteCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

Execute a database command that reads and writes on this server

Parameters

string $db

The name of the database on which to execute the command.

Command $command

The command to execute.

array|null $options

options Option Type Description readConcern MongoDB\Driver\ReadConcern A read concern to apply to the operation. This option is available in MongoDB 3.2+ and will result in an exception at execution time if specified for an older server version. session MongoDB\Driver\Session A session to associate with the operation. writeConcern MongoDB\Driver\WriteConcern A write concern to apply to the operation. If you are using a "session" which has a transaction in progress, you cannot specify a "readConcern" or "writeConcern" option. This will result in an MongoDB\Driver\Exception\InvalidArgumentException being thrown. Instead, you should set these two options when you create the transaction with MongoDB\Driver\Session::startTransaction.

Return Value

CursorInterface

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final CursorInterface executeWriteCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

Execute a database command that writes on this server

Parameters

string $db

The name of the database on which to execute the command.

Command $command

The command to execute.

array|null $options

options Option Type Description session MongoDB\Driver\Session A session to associate with the operation. writeConcern MongoDB\Driver\WriteConcern A write concern to apply to the operation. If you are using a "session" which has a transaction in progress, you cannot specify a "readConcern" or "writeConcern" option. This will result in an MongoDB\Driver\Exception\InvalidArgumentException being thrown. Instead, you should set these two options when you create the transaction with MongoDB\Driver\Session::startTransaction.

Return Value

CursorInterface

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final CursorInterface executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null)

Execute a database query on this server

Parameters

string $namespace

A fully qualified namespace (e.g. "databaseName.collectionName").

Query $query

The MongoDB\Driver\Query to execute.

array|ReadPreference|null $options

options Option Type Description readPreference MongoDB\Driver\ReadPreference A read preference to use for selecting a server for the operation. session MongoDB\Driver\Session A session to associate with the operation.

Return Value

CursorInterface

Returns MongoDB\Driver\Cursor on success.

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final string getHost()

Returns the hostname of this server

Return Value

string

Exceptions

InvalidArgumentException

final array getInfo()

Returns an array of information about this server

Return Value

array

Exceptions

InvalidArgumentException

final int getLatency()

Returns the latency of this server

Return Value

int

Exceptions

InvalidArgumentException

final int getPort()

Returns the port on which this server is listening

Return Value

int

Exceptions

InvalidArgumentException

final ServerDescription getServerDescription()

Since: 1.13.0

Return Value

ServerDescription

final array getTags()

Returns an array of tags describing this server in a replica set

Return Value

array

An array of tags used to describe this server in a replica set. The array will contain zero or more string key and value pairs.

Exceptions

InvalidArgumentException

final int getType()

Returns an integer denoting the type of this server

Return Value

int

denoting the type of this server

Exceptions

InvalidArgumentException

final bool isArbiter()

Checks if this server is an arbiter member of a replica set

Return Value

bool

Exceptions

InvalidArgumentException

final bool isHidden()

Checks if this server is a hidden member of a replica set

Return Value

bool

Exceptions

InvalidArgumentException

final bool isPassive()

Checks if this server is a passive member of a replica set

Return Value

bool

Exceptions

InvalidArgumentException

final bool isPrimary()

Checks if this server is a primary member of a replica set

Return Value

bool

Exceptions

InvalidArgumentException

final bool isSecondary()

Checks if this server is a secondary member of a replica set

Return Value

bool

Exceptions

InvalidArgumentException