Documentation

Client
in package

Table of Contents

$defaultTypeMap  : array<string|int, mixed>
$handshakeSeparator  : string
$manager  : Manager
$readConcern  : ReadConcern
$readPreference  : ReadPreference
$typeMap  : array<string|int, mixed>
$uri  : string
$version  : string|null
$writeConcern  : WriteConcern
__construct()  : mixed
Constructs a new Client instance.
__debugInfo()  : array<string|int, mixed>
Return internal properties for debugging purposes.
__get()  : Database
Select a database.
__toString()  : string
Return the connection string (i.e. URI).
createClientEncryption()  : ClientEncryption
Returns a ClientEncryption instance for explicit encryption and decryption
dropDatabase()  : array<string|int, mixed>|object
Drop a database.
getManager()  : Manager
Return the Manager.
getReadConcern()  : ReadConcern
Return the read concern for this client.
getReadPreference()  : ReadPreference
Return the read preference for this client.
getTypeMap()  : array<string|int, mixed>
Return the type map for this client.
getWriteConcern()  : WriteConcern
Return the write concern for this client.
listDatabaseNames()  : Iterator
List database names.
listDatabases()  : DatabaseInfoIterator
List databases.
selectCollection()  : Collection
Select a collection.
selectDatabase()  : Database
Select a database.
startSession()  : Session
Start a new client session.
watch()  : ChangeStream
Create a change stream for watching changes to the cluster.
getVersion()  : string
mergeDriverInfo()  : array<string|int, mixed>

Properties

$defaultTypeMap

private static array<string|int, mixed> $defaultTypeMap = ['array' => \MongoDB\Model\BSONArray::class, 'document' => \MongoDB\Model\BSONDocument::class, 'root' => \MongoDB\Model\BSONDocument::class]

$handshakeSeparator

private static string $handshakeSeparator = ' / '

$manager

private Manager $manager

$readConcern

private ReadConcern $readConcern

$readPreference

private ReadPreference $readPreference

$typeMap

private array<string|int, mixed> $typeMap

$version

private static string|null $version

$writeConcern

private WriteConcern $writeConcern

Methods

__construct()

Constructs a new Client instance.

public __construct([string $uri = 'mongodb://127.0.0.1/' ][, array<string|int, mixed> $uriOptions = [] ][, array<string|int, mixed> $driverOptions = [] ]) : mixed

This is the preferred class for connecting to a MongoDB server or cluster of servers. It serves as a gateway for accessing individual databases and collections.

Supported driver-specific options:

  • typeMap (array): Default type map for cursors and BSON documents.

Other options are documented in MongoDB\Driver\Manager::__construct().

Parameters
$uri : string = 'mongodb://127.0.0.1/'

MongoDB connection string

$uriOptions : array<string|int, mixed> = []

Additional connection string options

$driverOptions : array<string|int, mixed> = []

Driver-specific options

Tags
see
http://docs.mongodb.org/manual/reference/connection-string/
see
http://php.net/manual/en/mongodb-driver-manager.construct.php
see
http://php.net/manual/en/mongodb.persistence.php#mongodb.persistence.typemaps
throws
InvalidArgumentException

for parameter/option parsing errors

throws
InvalidArgumentException

for parameter/option parsing errors in the driver

throws
RuntimeException

for other driver errors (e.g. connection errors)

Return values
mixed

__toString()

Return the connection string (i.e. URI).

public __toString() : string
Return values
string

createClientEncryption()

Returns a ClientEncryption instance for explicit encryption and decryption

public createClientEncryption(array<string|int, mixed> $options) : ClientEncryption
Parameters
$options : array<string|int, mixed>

Encryption options

Return values
ClientEncryption

dropDatabase()

Drop a database.

public dropDatabase(string $databaseName[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
$databaseName : string

Database name

$options : array<string|int, mixed> = []

Additional options

Tags
see
DropDatabase::__construct()

for supported options

throws
UnsupportedException

if options are unsupported on the selected server

throws
InvalidArgumentException

for parameter/option parsing errors

throws
RuntimeException

for other driver errors (e.g. connection errors)

Return values
array<string|int, mixed>|object

Command result document

getManager()

Return the Manager.

public getManager() : Manager
Return values
Manager

getReadPreference()

Return the read preference for this client.

public getReadPreference() : ReadPreference
Return values
ReadPreference

getTypeMap()

Return the type map for this client.

public getTypeMap() : array<string|int, mixed>
Return values
array<string|int, mixed>

listDatabaseNames()

List database names.

public listDatabaseNames([array<string|int, mixed> $options = [] ]) : Iterator
Parameters
$options : array<string|int, mixed> = []
Tags
see
ListDatabaseNames::__construct()

for supported options

throws
UnexpectedValueException

if the command response was malformed

throws
InvalidArgumentException

for parameter/option parsing errors

throws
RuntimeException

for other driver errors (e.g. connection errors)

Return values
Iterator

selectCollection()

Select a collection.

public selectCollection(string $databaseName, string $collectionName[, array<string|int, mixed> $options = [] ]) : Collection
Parameters
$databaseName : string

Name of the database containing the collection

$collectionName : string

Name of the collection to select

$options : array<string|int, mixed> = []

Collection constructor options

Tags
see
Collection::__construct()

for supported options

throws
InvalidArgumentException

for parameter/option parsing errors

Return values
Collection

selectDatabase()

Select a database.

public selectDatabase(string $databaseName[, array<string|int, mixed> $options = [] ]) : Database
Parameters
$databaseName : string

Name of the database to select

$options : array<string|int, mixed> = []

Database constructor options

Tags
see
Database::__construct()

for supported options

throws
InvalidArgumentException

for parameter/option parsing errors

Return values
Database

watch()

Create a change stream for watching changes to the cluster.

public watch([array<string|int, mixed> $pipeline = [] ][, array<string|int, mixed> $options = [] ]) : ChangeStream
Parameters
$pipeline : array<string|int, mixed> = []

List of pipeline operations

$options : array<string|int, mixed> = []

Command options

Tags
see
Watch::__construct()

for supported options

throws
InvalidArgumentException

for parameter/option parsing errors

Return values
ChangeStream

getVersion()

private static getVersion() : string
Return values
string

mergeDriverInfo()

private mergeDriverInfo(array<string|int, mixed> $driver) : array<string|int, mixed>
Parameters
$driver : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results