Commit ef3bba89 authored by Jeremy Mikola's avatar Jeremy Mikola

DOCS-8719: MongoDB\Client example for SSL and auth

parent 63952aa1
...@@ -39,6 +39,9 @@ Errors/Exceptions ...@@ -39,6 +39,9 @@ Errors/Exceptions
Examples Examples
-------- --------
Connecting to a Replica Set
~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you do not specify a ``$uri`` value, the driver connects to a standalone 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 :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: 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: ...@@ -54,6 +57,48 @@ demonstrates how to connect to a replica set with a custom read preference:
] ]
); );
Connecting with SSL and Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example demonstrates how to connect to a MongoDB replica set with
SSL and authentication, as is used for `MongoDB Atlas
<https://cloud.mongodb.com/?jmp=docs>`_:
.. code-block:: php
<?php
$client = new MongoDB\Client(
'mongodb://myUsername:myPassword@rs1.example.com,rs2.example.com/?ssl=true&replicaSet=myReplicaSet&authSource=admin'
);
Alternatively, the authentication credentials and URI parameters may be
specified in the constructor's ``$uriOptions`` parameter:
.. code-block:: php
<?php
$client = new MongoDB\Client(
'mongodb://rs1.example.com,rs2.example.com/'
[
'username' => 'myUsername',
'password' => 'myPassword',
'ssl' => true,
'replicaSet' => 'myReplicaSet',
'authSource' => 'admin',
],
);
The driver supports additional :php:`SSL options
<mongodb-driver-manager.construct#mongodb-driver-manager.construct-driveroptions>`,
which may be specified in the constructor's ``$driverOptions`` parameter. Those
options are covered in the :php:`MongoDB\\Driver\\Manager::__construct()
<mongodb-driver-manager.construct>` documentation.
Specifying a Custom Type Map
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default, the |php-library| deserializes BSON documents and arrays By default, the |php-library| deserializes BSON documents and arrays
as :phpclass:`MongoDB\\Model\\BSONDocument` and as :phpclass:`MongoDB\\Model\\BSONDocument` and
:phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following :phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment