@@ -9,7 +9,7 @@ Choose a Connection Target
9
9
:values: reference
10
10
11
11
.. meta::
12
- :keywords: connection string, URI, server, settings, client
12
+ :keywords: connection string, URI, server, settings, client, load balancing
13
13
14
14
.. contents:: On this page
15
15
:local:
@@ -74,6 +74,15 @@ Replica Sets
74
74
To connect to a replica set, specify the hostnames (or IP addresses) and
75
75
port numbers of the replica-set members in your connection string.
76
76
77
+ The following code shows how to use {+driver-short+} to connect to a replica set
78
+ that contains three hosts:
79
+
80
+ .. code-block:: python
81
+
82
+ from pymongo import MongoClient
83
+
84
+ client = MongoClient("mongodb://host1:27017,host2:27017,host3:27017")
85
+
77
86
If you aren't able to provide a full list of hosts in the replica set, you can
78
87
specify one or more of the hosts in the replica set and instruct {+driver-short+} to
79
88
perform automatic discovery to find the others. To instruct the driver to perform
@@ -94,6 +103,11 @@ hosts, including ``host1``:
94
103
uri = "mongodb://host1:27017/?replicaSet=sampleRS"
95
104
client = MongoClient(uri)
96
105
106
+ {+driver-short+} evenly load balances operations across deployments that are reachable
107
+ within the client's ``localThresholdMS`` value. To learn more about how {+driver-short+} load
108
+ balances operations across multiple MongoDB deployments, see the
109
+ :ref:`pymongo-server-selection` guide.
110
+
97
111
.. note::
98
112
99
113
The ``MongoClient`` constructor is *non-blocking*.
0 commit comments