Skip to content

Commit ef3bba8

Browse files
committed
DOCS-8719: MongoDB\Client example for SSL and auth
1 parent 63952aa commit ef3bba8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/reference/method/MongoDBClient__construct.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Errors/Exceptions
3939
Examples
4040
--------
4141

42+
Connecting to a Replica Set
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
44+
4245
If you do not specify a ``$uri`` value, the driver connects to a standalone
4346
:program:`mongod` on ``127.0.0.1`` via port ``27017``. The following example
4447
demonstrates how to connect to a replica set with a custom read preference:
@@ -54,6 +57,48 @@ demonstrates how to connect to a replica set with a custom read preference:
5457
]
5558
);
5659

60+
Connecting with SSL and Authentication
61+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62+
63+
The following example demonstrates how to connect to a MongoDB replica set with
64+
SSL and authentication, as is used for `MongoDB Atlas
65+
<https://cloud.mongodb.com/?jmp=docs>`_:
66+
67+
.. code-block:: php
68+
69+
<?php
70+
71+
$client = new MongoDB\Client(
72+
'mongodb://myUsername:[email protected],rs2.example.com/?ssl=true&replicaSet=myReplicaSet&authSource=admin'
73+
);
74+
75+
Alternatively, the authentication credentials and URI parameters may be
76+
specified in the constructor's ``$uriOptions`` parameter:
77+
78+
.. code-block:: php
79+
80+
<?php
81+
82+
$client = new MongoDB\Client(
83+
'mongodb://rs1.example.com,rs2.example.com/'
84+
[
85+
'username' => 'myUsername',
86+
'password' => 'myPassword',
87+
'ssl' => true,
88+
'replicaSet' => 'myReplicaSet',
89+
'authSource' => 'admin',
90+
],
91+
);
92+
93+
The driver supports additional :php:`SSL options
94+
<mongodb-driver-manager.construct#mongodb-driver-manager.construct-driveroptions>`,
95+
which may be specified in the constructor's ``$driverOptions`` parameter. Those
96+
options are covered in the :php:`MongoDB\\Driver\\Manager::__construct()
97+
<mongodb-driver-manager.construct>` documentation.
98+
99+
Specifying a Custom Type Map
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101+
57102
By default, the |php-library| deserializes BSON documents and arrays
58103
as :phpclass:`MongoDB\\Model\\BSONDocument` and
59104
:phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following

0 commit comments

Comments
 (0)