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
$uri
private
string
$uri
$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
Return values
mixed —__debugInfo()
Return internal properties for debugging purposes.
public
__debugInfo() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —__get()
Select a database.
public
__get(string $databaseName) : Database
Note: databases whose names contain special characters (e.g. "-") may be selected with complex syntax (e.g. $client->{"that-database"}) or .
Parameters
- $databaseName : string
-
Name of the database to select
Tags
Return values
Database —__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
Return values
array<string|int, mixed>|object —Command result document
getManager()
Return the Manager.
public
getManager() : Manager
Return values
Manager —getReadConcern()
Return the read concern for this client.
public
getReadConcern() : ReadConcern
Tags
Return values
ReadConcern —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> —getWriteConcern()
Return the write concern for this client.
public
getWriteConcern() : WriteConcern
Tags
Return values
WriteConcern —listDatabaseNames()
List database names.
public
listDatabaseNames([array<string|int, mixed> $options = [] ]) : Iterator
Parameters
- $options : array<string|int, mixed> = []
Tags
Return values
Iterator —listDatabases()
List databases.
public
listDatabases([array<string|int, mixed> $options = [] ]) : DatabaseInfoIterator
Parameters
- $options : array<string|int, mixed> = []
Tags
Return values
DatabaseInfoIterator —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
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
Return values
Database —startSession()
Start a new client session.
public
startSession([array<string|int, mixed> $options = [] ]) : Session
Parameters
- $options : array<string|int, mixed> = []
-
Session options
Tags
Return values
Session —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
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>