Skip to content

Commit 5f06c44

Browse files
committed
replica set
1 parent 54aa80a commit 5f06c44

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

source/connect.txt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,25 @@ Replica Set
105105

106106
The following code shows how to connect to a replica set deployment:
107107

108-
.. literalinclude:: /includes/usage-examples/connect-code-examples.php
109-
:language: php
110-
:dedent:
111-
:start-after: start-replica-set
112-
:end-before: end-replica-set
108+
.. tabs::
109+
110+
.. tab:: MongoDB\\Client
111+
:tabid: Client
112+
113+
.. literalinclude:: /includes/usage-examples/connect-code-examples.php
114+
:language: php
115+
:dedent:
116+
:start-after: start-replica-set-client
117+
:end-before: end-replica-set-client
118+
119+
.. tab:: Connection URI
120+
:tabid: connectionstring
121+
122+
.. literalinclude:: /includes/usage-examples/connect-code-examples.php
123+
:language: php
124+
:dedent:
125+
:start-after: start-replica-set-uri
126+
:end-before: end-replica-set-uri
113127

114128
To learn more about connecting to a replica set, see :ref:`php-connection-replica-set`
115129
in the Connection Targets guide.

source/includes/usage-examples/connect-code-examples.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
$client = new MongoDB\Client($uri);
1515
// end-atlas
1616

17-
// Connects to a replica set
18-
// start-replica-set
17+
// Connects to a replica set using client options
18+
// start-replica-set-client
19+
$client = new MongoDB\Client(
20+
'mongodb://<replica set member>:<port>/',
21+
['replicaSet' => '<replica set name>'],
22+
);
23+
// end-replica-set-client
24+
25+
// Connects to a replica set using a connection URI parameter
26+
// start-replica-set-uri
1927
$uri = 'mongodb://<replica set member>:<port>/?replicaSet=<replica set name>';
2028
$client = new MongoDB\Client($uri);
21-
// end-replica-set
29+
// end-replica-set-uri
2230

2331
// Connects to a MongoDB deployment and enables TLS using client
2432
// options

0 commit comments

Comments
 (0)