@@ -39,6 +39,9 @@ Errors/Exceptions
39
39
Examples
40
40
--------
41
41
42
+ Connecting to a Replica Set
43
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
+
42
45
If you do not specify a ``$uri`` value, the driver connects to a standalone
43
46
:program:`mongod` on ``127.0.0.1`` via port ``27017``. The following example
44
47
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
57
]
55
58
);
56
59
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
+
57
102
By default, the |php-library| deserializes BSON documents and arrays
58
103
as :phpclass:`MongoDB\\Model\\BSONDocument` and
59
104
:phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following
0 commit comments