Skip to content

DOCSP-46695: Add extra info on load balancing to connection targets page #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion source/connect/connection-targets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Choose a Connection Target
:values: reference

.. meta::
:keywords: connection string, URI, server, settings, client
:keywords: connection string, URI, server, settings, client, load balancing

.. contents:: On this page
:local:
Expand Down Expand Up @@ -74,6 +74,15 @@ Replica Sets
To connect to a replica set, specify the hostnames (or IP addresses) and
port numbers of the replica-set members in your connection string.

The following code shows how to use {+driver-short+} to connect to a replica set
that contains three hosts:

.. code-block:: python

from pymongo import MongoClient

client = MongoClient("mongodb://host1:27017,host2:27017,host3:27017")

If you aren't able to provide a full list of hosts in the replica set, you can
specify one or more of the hosts in the replica set and instruct {+driver-short+} to
perform automatic discovery to find the others. To instruct the driver to perform
Expand All @@ -94,6 +103,11 @@ hosts, including ``host1``:
uri = "mongodb://host1:27017/?replicaSet=sampleRS"
client = MongoClient(uri)

{+driver-short+} evenly load balances operations across deployments that are reachable
within the client's ``localThresholdMS`` value. To learn more about how {+driver-short+} load
balances operations across multiple MongoDB deployments, see the
:ref:`pymongo-server-selection` guide.

.. note::

The ``MongoClient`` constructor is *non-blocking*.
Expand Down
Loading