Skip to content

Commit caf15dd

Browse files
committed
DOCSP-47072: Client parameters
1 parent 1aea063 commit caf15dd

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

source/connect/client.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,31 @@ Server manual.
8686
Create a MongoDB\Client
8787
-----------------------
8888

89-
To create a connection to MongoDB, pass your connection string when constructing
90-
an instance of the ``MongoDB\Client`` class.
89+
To create a connection to MongoDB, construct a ``MongoDB\Client`` object.
90+
Pass the following parameters to the ``MongoDB\Client`` constructor:
9191

92-
In the following example, the library uses a sample connection URI to connect to a MongoDB
93-
deployment on port ``27017`` of ``localhost``:
92+
- ``$uri``: Sets the connection string.
93+
94+
- ``$uriOptions``: *(Optional)* Sets URI options to configure how the client
95+
connects to MongoDB, including authentication credentials and
96+
and server selection settings. If you set the same options in this
97+
parameter and in your connection string, the ``$uriOptions`` values
98+
take precedence. To view a full list of supported options, see
99+
the :ref:`php-connection-options` guide.
100+
101+
- ``$driverOptions``: *(Optional)* Sets options to configure the behavior of the
102+
underlying {+extension-short+}, including data encryption settings and certificate
103+
validation options for TLS connections. To view a full list of supported options,
104+
see :phpmethod:`MongoDB\Client::__construct()` in the {+library-short+} API
105+
documentation.
106+
107+
This example constructs a client and passes the following parameters:
108+
109+
- Connection URI, which connects to a MongoDB deployment on port ``27017``
110+
of ``localhost``
111+
112+
- URI options parameter, which instructs the {+library-short+} to wait
113+
``10000`` milliseconds for server selection before generating an error
94114

95115
.. literalinclude:: /includes/connect/client.php
96116
:language: php

source/includes/connect/client.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
22

3-
$client = new MongoDB\Client('mongodb://localhost:27017');
3+
$uri = 'mongodb://localhost:27017';
4+
$uriOptions = ['serverSelectionTimeoutMS' => 10000];
5+
6+
$client = new MongoDB\Client($uri, $uriOptions);

0 commit comments

Comments
 (0)