Skip to content

Commit 292ca61

Browse files
authored
Merge branch 'master' into docsp-46687-collations
2 parents da414e2 + ee9153f commit 292ca61

21 files changed

+736
-31
lines changed

.github/pull_request_template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[PR Reviewing Guidelines](https://github.com/mongodb/docs-node/blob/master/REVIEWING.md)
44

55
JIRA - <https://jira.mongodb.org/browse/DOCSP-NNNNN>
6-
Staging - <https://docs-mongodbcom-staging.corp.mongodb.com/drivers/docsworker-xlarge/NNNNN/>
6+
7+
### Staging Links
8+
<!-- start insert-links --><!-- end insert-links -->
79

810
## Self-Review Checklist
911

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Add Netlify Links To Changed Pages
2+
on:
3+
workflow_call:
4+
pull_request_target:
5+
jobs:
6+
get-pr-changes:
7+
name: Get Changed Files & Update PR Description
8+
runs-on: ubuntu-latest
9+
permissions:
10+
issues: write
11+
contents: write
12+
pull-requests: write
13+
repository-projects: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Get Changed Files
17+
id: changed-files
18+
# pin to a specific commit to ensure stability
19+
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
20+
with:
21+
separator: ","
22+
files: source/**
23+
- name: Build Netlify Links for Changed Pages
24+
id: build_page_links
25+
env:
26+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
27+
run: |
28+
new_links=""
29+
base_link='https://deploy-preview-${{ github.event.number }}--docs-pymongo.netlify.app'
30+
files=$(echo "$CHANGED_FILES" | tr "," "\n")
31+
for file in $files; do
32+
echo "processing ${file}"
33+
if (! grep -s "includes/" <<< "$file") &&
34+
(! grep -s "images/" <<< "$file") &&
35+
(! grep -s "examples/" <<< "$file"); then
36+
file="${file#source}"
37+
file="${file%.txt}"
38+
filenoslash="${file:1}"
39+
echo "${base_link}${file}"
40+
new_links+="<li><a href=${base_link}${file}>${filenoslash}</a></li>"
41+
else
42+
echo "(file skipped)"
43+
fi
44+
done
45+
if [ "$new_links" == "" ]; then
46+
new_links="No pages to preview"
47+
fi
48+
echo "Final new_links string: "
49+
echo "${new_links}"
50+
echo "staging_links=${new_links}" >> "$GITHUB_OUTPUT"
51+
- name: Update the PR Description
52+
uses: MongoCaleb/pr-description-action@master
53+
with:
54+
regex: "<!-- start insert-links -->.*<!-- end insert-links -->"
55+
appendContentOnMatchOnly: true
56+
regexFlags: is
57+
content: "<!-- start insert-links -->\n${{ steps.build_page_links.outputs.staging_links }}\n<!-- end insert-links -->"
58+
token: ${{ secrets.GITHUB_TOKEN }}

config/redirects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define: prefix docs/languages/python/pymongo-driver
22
define: base https://www.mongodb.com/${prefix}
3-
define: versions v4.0 v4.1 v4.2 v4.3 v4.4 v4.5 v4.6 v4.7 v4.8 v4.9 4.10 master
3+
define: versions v4.0 v4.1 v4.2 v4.3 v4.4 v4.5 v4.6 v4.7 v4.8 v4.9 4.10 4.11 master
44

55
symlink: current -> master
66

snooty.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ mdb-server = "MongoDB Server"
3131
mongo-community = "MongoDB Community Edition"
3232
mongo-enterprise = "MongoDB Enterprise Edition"
3333
docs-branch = "master" # always set this to the docs branch (i.e. master, 1.7, 1.8, etc.)
34-
version-number = "4.10"
35-
patch-version-number = "{+version-number+}.1" # always set this to the driver branch (i.e. 1.7.0, 1.8.0, etc.)
34+
version-number = "4.11"
35+
patch-version-number = "{+version-number+}" # always set this to the driver branch (i.e. 1.7.0, 1.8.0, etc.)
3636
version = "v{+version-number+}"
3737
stable-api = "Stable API"
3838
api-root = "https://pymongo.readthedocs.io/en/{+patch-version-number+}/api/"
3939
string-data-type = "``str``"
4040
int-data-type = "``int``"
4141
bool-data-type = "``bool``"
42+
django-odm = "Django MongoDB Backend"
43+
django-docs = "https://www.mongodb.com/docs/languages/python/django-mongodb/current"
44+
45+
[[banners]]
46+
targets = ["index.txt"]
47+
variant = "tip"
48+
value = """
49+
{+django-odm+} is now in Public Preview! \
50+
To discover its features and learn more, see the `{+django-odm+} documentation <{+django-docs+}>`__.
51+
"""

source/connect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Connect to MongoDB
3030
Customize Server Selection </connect/server-selection>
3131
Stable API </connect/stable-api>
3232
Limit Server Execution Time </connect/csot>
33+
Connection Pools </connect/connection-pools>
3334

3435
Overview
3536
--------

source/connect/connection-options.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,28 @@ Read and Write Operations
258258
time plus this value, the server isn't eligible for selection.
259259
|
260260
| **Data Type**: `read_preferences <{+api-root+}pymongo/read_preferences.html#pymongo.read_preferences>`__
261-
| **Default**: ``{+int-data-type+}``
261+
| **Default**: {+int-data-type+}
262262
| **MongoClient Example**: ``localThresholdMS=35``
263263
| **Connection URI Example**: ``localThresholdMS=35``
264264

265-
For more information about the connection option in this section, see :ref:`pymongo-databases-collections`.
265+
* - **retryReads**
266+
- | Specifies whether the client retries supported read operations. For more
267+
information, see :manual:`Retryable Reads </core/retryable-reads/>` in the {+mdb-server+}
268+
manual.
269+
|
270+
| **Data Type**: {+bool-data-type+}
271+
| **Default**: ``True``
272+
| **MongoClient Example**: ``retryReads=False``
273+
| **Connection URI Example**: ``retryReads=false``
274+
275+
* - **retryWrites**
276+
- | Specifies whether the client retries supported write operations. For more
277+
information, see :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+}
278+
manual.
279+
|
280+
| **Data Type**: {+bool-data-type+}
281+
| **Default**: ``True``
282+
| **MongoClient Example**: ``retryWrites=False``
283+
| **Connection URI Example**: ``retryWrites=false``
284+
285+
For more information about the connection options in this section, see :ref:`pymongo-databases-collections`.

source/connect/connection-pools.txt

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
.. _pymongo-connection-pools:
2+
3+
================
4+
Connection Pools
5+
================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. contents:: On this page
12+
:local:
13+
:backlinks: none
14+
:depth: 2
15+
:class: singlecol
16+
17+
Overview
18+
--------
19+
20+
In this guide, you can learn about how {+driver-short+} uses connection pools to manage
21+
connections to a MongoDB deployment and how you can configure connection pool settings
22+
in your application.
23+
24+
A connection pool is a cache of open database connections maintained by {+driver-short+}.
25+
When your application requests a connection to MongoDB, {+driver-short+} seamlessly
26+
gets a connection from the pool, performs operations, and returns the connection
27+
to the pool for reuse.
28+
29+
Connection pools help reduce application latency and the number of times new connections
30+
are created by {+driver-short+}.
31+
32+
Configuring Connection Pools
33+
----------------------------
34+
35+
You can specify the following connection pool settings in your ``MongoClient`` object or in
36+
your connection URI:
37+
38+
.. list-table::
39+
:widths: 30 70
40+
:header-rows: 1
41+
42+
* - Setting
43+
- Description
44+
45+
* - ``connectTimeoutMS``
46+
- | Sets the time that {+driver-short+} waits when connecting a new
47+
socket before timing out.
48+
| Defaults to ``20000``
49+
50+
* - ``maxConnecting``
51+
- | Sets the maximum number of connections that each pool can establish concurrently.
52+
If this limit is reached, further requests wait until a connection is established
53+
or another in-use connection is checked back into the pool.
54+
| Defaults to ``2``
55+
56+
* - ``maxIdleTimeMS``
57+
- | Sets the maximum time that a connection can remain idle in the pool.
58+
| Defaults to ``None`` (no limit)
59+
60+
* - ``maxPoolSize``
61+
- | Sets the maximum number of concurrent connections that the pool maintains.
62+
If the maximum pool size is reached, further requests wait until a connection
63+
becomes available.
64+
| Defaults to ``100``
65+
66+
* - ``minPoolSize``
67+
- | Sets the minimum number of concurrent connections that the pool maintains. If
68+
the number of open connections falls below this value due to network errors,
69+
{+driver-short+} attempts to create new connections to maintain this minimum.
70+
| Defaults to ``0``
71+
72+
* - ``socketTimeoutMS``
73+
- | Sets the length of time that {+driver-short+} waits for a response from the server
74+
before timing out.
75+
| Defaults to ``None`` (no timeout)
76+
77+
* - ``waitQueueTimeoutMS``
78+
- | Sets how long a thread waits for a connection to become available in the connection pool
79+
before timing out.
80+
| Defaults to ``None`` (no timeout)
81+
82+
The following code creates a client with a maximum connection pool size of ``50`` by using the
83+
``maxPoolSize`` parameter:
84+
85+
.. code-block:: python
86+
87+
client = MongoClient(host, port, maxPoolSize=50)
88+
89+
The following code creates a client with the same configuration as the preceding example,
90+
but uses a connection URI:
91+
92+
.. code-block:: python
93+
94+
client = MongoClient("mongodb://<host>:<port>/?maxPoolSize=50")
95+
96+
Additional Information
97+
----------------------
98+
99+
To learn more about connection pools, see :manual:`Connection Pool Overview </administration/connection-pool-overview/>`
100+
in the {+mdb-server+} manual.
101+
102+
API Documentation
103+
~~~~~~~~~~~~~~~~~
104+
105+
To learn more about any of the methods or types discussed in this
106+
guide, see the following API documentation:
107+
108+
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__

source/connect/connection-targets.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Choose a Connection Target
99
:values: reference
1010

1111
.. meta::
12-
:keywords: connection string, URI, server, settings, client
12+
:keywords: connection string, URI, server, settings, client, load balancing
1313

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

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

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+
97111
.. note::
98112

99113
The ``MongoClient`` constructor is *non-blocking*.

source/connect/mongoclient.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,77 @@ instance on port ``27017`` of ``localhost``:
9797
uri = "mongodb://localhost:27017/"
9898
client = MongoClient(uri)
9999

100+
The following table describes the positional parameters that the ``MongoClient()``
101+
constructor accepts. All parameters are optional.
102+
103+
.. list-table::
104+
:widths: 20 80
105+
:header-rows: 1
106+
107+
* - Parameter
108+
- Description
109+
110+
* - ``host``
111+
- The hostname, IP address, or Unix domain socket path of the MongoDB deployment.
112+
If your application connects to a replica set or sharded cluster, you can specify
113+
multiple hostnames or IP addresses in a Python list.
114+
115+
If you pass a literal IPv6 address, you must enclose the address in square brackets
116+
(``[ ]``). For example, pass the value ``[::1]`` to connect to localhost.
117+
118+
{+driver-short+} doesn't support :wikipedia:`multihomed <Multihoming>` and
119+
:wikipedia:`round-robin DNS <Round-robin_DNS>` addresses.
120+
121+
**Data type:** ``Union[str, Sequence[str]]``
122+
**Default value:** ``"localhost"``
123+
124+
* - ``port``
125+
- The port number {+mdb-server+} is running on.
126+
127+
You can include the port number in the ``host`` argument
128+
instead of using this parameter.
129+
130+
**Data type:** ``int``
131+
**Default value:** ``27017``
132+
133+
* - ``document_class``
134+
- The default class that the client uses to decode BSON documents returned by queries.
135+
This parameter supports the ``bson.raw_bson.RawBSONDocument`` type, as well as
136+
subclasses of the ``collections.abc.Mapping`` type, such as ``bson.son.SON``.
137+
138+
If you specify ``bson.son.SON`` as the document class, you must also specify types
139+
for the key and value.
140+
141+
**Data type:** ``Type[_DocumentType]``
142+
143+
* - ``tz_aware``
144+
- If this parameter is ``True``, the client treats ``datetime`` values as aware.
145+
Otherwise, it treats them as naive.
146+
147+
For more information about aware and naive ``datetime`` values, see
148+
`datetime <https://docs.python.org/3/library/datetime.html>`__ in the Python
149+
documentation.
150+
151+
**Data type:** ``bool``
152+
153+
* - ``connect``
154+
- If this parameter is ``True``, the client begins connecting to MongoDB
155+
in the background immediately after you create it. If this parameter is ``False``,
156+
the client connects to MongoDB when it performs the first database operation.
157+
158+
If your application is running in a
159+
:wikipedia:`function-as-a-service (FaaS) <Function_as_a_service>`
160+
environment, the default value is ``False``. Otherwise, the default value is ``True``.
161+
162+
**Data type:** ``bool``
163+
164+
* - ``type_registry``
165+
- An instance of the ``TypeRegistry`` class to enable encoding and decoding of
166+
custom types. For more information about encoding and decoding custom types,
167+
see :ref:`pymongo-custom-types`.
168+
169+
**Data type:** `TypeRegistry <{+api-root+}bson/codec_options.html#bson.codec_options.TypeRegistry>`__
170+
100171
.. tip:: Reusing Your Client
101172

102173
Because each ``MongoClient`` object represents a pool of connections to the
@@ -105,6 +176,28 @@ instance on port ``27017`` of ``localhost``:
105176
a process, the child process *does* need its own ``MongoClient`` object.
106177
To learn more, see the :ref:`FAQ <pymongo-faq>` page.
107178

179+
Type Hints
180+
----------
181+
182+
If you're using Python v3.5 or later, you can add type hints to your Python code.
183+
184+
The following code example shows how to declare a type hint for a ``MongoClient``
185+
object:
186+
187+
.. code-block:: python
188+
189+
client: MongoClient = MongoClient()
190+
191+
In the previous example, the code doesn't specify a type for the documents that the
192+
``MongoClient`` object will work with. To specify a document type,
193+
include the ``Dict[str, Any]`` type when you
194+
create the ``MongoClient`` object, as shown in the following example:
195+
196+
.. code-block:: python
197+
198+
from typing import Any, Dict
199+
client: MongoClient[Dict[str, Any]] = MongoClient()
200+
108201
API Documentation
109202
-----------------
110203

0 commit comments

Comments
 (0)