============================== MongoDB\\Client::__construct() ============================== .. default-domain:: mongodb .. contents:: On this page :local: :backlinks: none :depth: 1 :class: singlecol Definition ---------- .. phpmethod:: MongoDB\\Client::__construct() Constructs a new :phpclass:`Client ` instance. .. code-block:: php function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = []) This constructor has the following parameters: .. include:: /includes/apiargs/MongoDBClient-method-construct-param.rst The ``$driverOptions`` parameter supports the following options: .. include:: /includes/apiargs/MongoDBClient-method-construct-driverOptions.rst Examples -------- If you do not specify a ``$uri`` value, the driver connects to a standalone :program:`mongod` on ``127.0.0.1`` via port ``27017``. The following example demonstrates how to connect to a replica set with a custom read preference: .. code-block:: php 'secondaryPreferred', ] ); By default, the |php-library| deserializes BSON documents and arrays as :phpclass:`MongoDB\\Model\\BSONDocument` and :phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following example demonstrates how to have the library unserialize everything as a PHP array, as was done in the legacy :php:`mongo extension `. .. code-block:: php [ 'root' => 'array', 'document' => 'array', 'array' => 'array', ], ] ); See Also -------- - :php:`MongoDB\\Driver\\Manager::__construct() `