Skip to content

Commit 34cb440

Browse files
authored
Merge branch 'master' into DOCSP-46691-connection-pools
2 parents b41a340 + 11167f1 commit 34cb440

File tree

10 files changed

+264
-24
lines changed

10 files changed

+264
-24
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ 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/"

source/connect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Connect to MongoDB
3131
Stable API </connect/stable-api>
3232
Limit Server Execution Time </connect/csot>
3333
Connection Pools </connect/connection-pools>
34+
Compression </connect/compression>
3435

3536
Overview
3637
--------

source/connect/compression.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.. _pymongo-compression:
2+
3+
===========
4+
Compression
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 how to use compression algorithms with
21+
{+driver-short+}.
22+
23+
You can use compression to reduce the size of messages sent between your application
24+
and a MongoDB deployment. {+driver-short+} supports the following compression algorithms:
25+
26+
- `Snappy <https://google.github.io/snappy/>`__: You can use Snappy compression
27+
with MongoDB 3.4 and later by including the `python-snappy <https://pypi.org/project/python-snappy/>`__
28+
package in your application.
29+
- `Zlib <https://zlib.net/>`__: You can use Zlib compression with MongoDB 3.6 and later
30+
by including the `zlib <https://docs.python.org/3/library/zlib.html>`__ package
31+
in your application.
32+
- `Zstandard <https://github.com/facebook/zstd/>`__: You can use Zstandard compression
33+
with MongoDB 4.2 and later by including the `zstandard <https://pypi.org/project/zstandard/>`__
34+
package in your application.
35+
36+
Specifying Compression By Using a Connection String
37+
---------------------------------------------------
38+
39+
You can specify the compression algorithm to use by including the ``compressors`` option
40+
in your connection string. The following example specifies the Snappy compression algorithm
41+
42+
.. code-block:: python
43+
44+
client = pymongo.MongoClient("mongodb://localhost/?compressors=snappy")
45+
46+
You can also specify multiple compression algorithms by separating them with a comma, as
47+
show in the following example:
48+
49+
.. code-block:: python
50+
51+
client = pymongo.MongoClient("mongodb://localhost/?compressors=snappy,zlib,zstd")
52+
53+
.. note::
54+
55+
When you supply multiple compression algorithms to a connection string,
56+
{+driver-short+} uses the first compression algorithm in the list that the
57+
deployment supports.
58+
59+
Specifying Compression to a MongoClient
60+
---------------------------------------
61+
62+
You can also specify the compression algorithm to use by passing the algorithms to use
63+
to the ``compressors`` parameter of the ``MongoClient`` constructor, as shown in the
64+
following example:
65+
66+
.. code-block:: python
67+
68+
client = pymongo.MongoClient(compressors="snappy")
69+
70+
You can also specify multiple compression algorithms by passing a list of algorithms to the
71+
``MongoClient`` constructor, as shown in the following example:
72+
73+
.. code-block:: python
74+
75+
client = pymongo.MongoClient(compressors=["snappy", "zlib", "zstd"])
76+
77+
.. note::
78+
79+
When you supply multiple compression algorithms to a ``MongoClient``,
80+
{+driver-short+} uses the first compression algorithm in the list that the
81+
deployment supports.
82+
83+
API Documentation
84+
-----------------
85+
86+
To learn more about any of the methods or types discussed in this
87+
guide, see the following API documentation:
88+
89+
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__

source/data-formats.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Specialized Data Formats
2121
:titlesonly:
2222
:maxdepth: 1
2323

24+
BSON </data-formats/bson>
2425
Custom Types </data-formats/custom-types>
2526
Dates & Times </data-formats/dates-and-times>
2627
UUIDs </data-formats/uuid>
@@ -33,6 +34,7 @@ You can use several types of specialized data formats in your {+driver-short+}
3334
application. To learn how to work with these data formats, see the following
3435
sections:
3536

37+
- Learn how to work with BSON documents in the :ref:`pymongo-bson` guide.
3638
- Learn how to encode and decode custom types in the :ref:`pymongo-custom-types` guide.
3739
- Learn how to work with Python ``datetime`` objects in {+driver-short+} in the
3840
:ref:`pymongo-dates-times` guide.

source/data-formats/bson.txt

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
.. _pymongo-bson:
2+
3+
====
4+
BSON
5+
====
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 2
13+
:class: singlecol
14+
15+
Overview
16+
--------
17+
18+
In this guide, you can learn how to create BSON documents, read BSON from a file,
19+
and write BSON to a file by using {+driver-short+}.
20+
21+
**BSON**, or Binary JSON, is the data format that MongoDB uses to organize
22+
and store data. This data format includes all JSON data structure types and
23+
adds support for types including dates, different size integers, ObjectIds, and
24+
binary data. You can use BSON documents in your {+language+} application by including the
25+
`bson <{+api-root+}bson/index.html>`__ package. For a complete list of supported types, see the
26+
:manual:`BSON Types </reference/bson-types>` server manual page.
27+
28+
The code samples in this guide use the following BSON document as an example:
29+
30+
.. code-block:: none
31+
32+
{
33+
"address" : {
34+
"street" : "Pizza St",
35+
"zipcode" : "10003"
36+
},
37+
"coord" : [-73.982419, 41.579505]
38+
"cuisine" : "Pizza",
39+
"name" : "Mongo's Pizza"
40+
}
41+
42+
Create a BSON Document
43+
----------------------
44+
45+
You can create a BSON document by using the same notation you use to create a
46+
dictionary in {+language+}. {+driver-short+} automatically converts {+language+} dictionaries
47+
into BSON documents when inserting them into a collection.
48+
49+
The following example creates a BSON document that
50+
represents the preceding sample BSON document:
51+
52+
.. code-block:: python
53+
54+
document = {
55+
"address": {
56+
"street": "Pizza St",
57+
"zipcode": "10003"
58+
},
59+
"coord": [-73.982419, 41.579505],
60+
"cuisine": "Pizza",
61+
"name": "Mongo's Pizza"
62+
}
63+
64+
Change a BSON Document
65+
----------------------
66+
67+
You can modify the contents of a BSON document by using the same notation you use to modify
68+
a dictionary in {+language+}. The following example makes three changes to the previous
69+
BSON document:
70+
71+
1. Adds a new field, ``restaurant_id``, with the value ``12345``
72+
#. Removes the ``cuisine`` field
73+
#. Sets the value of the ``name`` field to ``"Mongo's Pizza Place"``
74+
75+
.. code-block:: python
76+
77+
document["restaurant_id"] = 12345
78+
del document["cuisine"]
79+
document["name"] = "Mongo's Pizza Place"
80+
81+
Write BSON to a File
82+
--------------------
83+
84+
To write BSON data to a file, open a file stream in write-binary mode on the output file.
85+
Then, write each document to the output file. Ensure that documents are encoded in BSON
86+
format by using the ``bson.encode()`` method.
87+
88+
The following example writes the sample BSON document to ``file.bson``:
89+
90+
.. code-block:: python
91+
92+
with open("file.bson", "w") as file:
93+
file.write(bson.encode(document))
94+
95+
Read BSON from a File
96+
---------------------
97+
98+
To read BSON documents from a file, open a file stream in read-binary mode on the input
99+
file. Then, decode the documents from BSON format as you read them by using the ``bson.decode()``
100+
method.
101+
102+
The following example reads the sample BSON document from ``file.bson``:
103+
104+
.. io-code-block::
105+
:copyable: true
106+
107+
.. input::
108+
:language: python
109+
110+
with open("file.bson", "rb") as file:
111+
data = file.read()
112+
document = bson.decode(data)
113+
print(document)
114+
115+
.. output::
116+
:visible: false
117+
118+
{"address": {"street": "Pizza St", "zipcode": "10003"}, "coord": [-73.982419, 41.579505], "cuisine": "Pizza", "name": "Mongo's Pizza"}
119+
120+
API Documentation
121+
-----------------
122+
123+
To learn more about any of the methods or types discussed in this
124+
guide, see the `bson <{+api-root+}bson/index.html>`__ API documentation.

source/includes/language-compatibility-table-pymongo.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ Python 3
1919
- CPython 3.4
2020
- PyPy3
2121

22-
* - 4.10
23-
- ✓
22+
* - 4.11
2423
- ✓
2524
- ✓
2625
- ✓
2726
- ✓
2827
- ✓
28+
-
2929
-
3030
-
3131
-
3232
-
3333
-
3434

35-
* - 4.9
35+
* - 4.9 to 4.10
3636
- ✓
3737
- ✓
3838
- ✓
@@ -193,10 +193,6 @@ Python 3
193193
:ref:`TLS <pymongo-troubleshoot-tls>` section of the Troubleshooting guide.
194194
.. [#three-six-compat] Pymongo 4.1 requires Python 3.6.2 or later.
195195
196-
.. note::
197-
198-
PyPy3 is a Python 3.2-compatible alternative interpreter.
199-
200196
Python 2
201197
~~~~~~~~
202198

source/includes/mongodb-compatibility-table-pymongo.rst

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@
2323
- ✓
2424
-
2525

26-
* - 4.10
27-
- ✓
28-
- ✓
29-
- ✓
30-
- ✓
31-
- ✓
32-
- ✓
33-
- ✓
34-
- ✓
35-
36-
* - 4.9
26+
* - 4.9 to 4.10
3727
- ✓
3828
- ✓
3929
- ✓

source/upgrade.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,20 @@ and upgrade versions.
109109
Version 4.11 Breaking Changes
110110
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111111

112-
- {+mdb-server+} v3.6 is no longer supported. The minimum supported {+mdb-server+}
112+
- Drops support for {+mdb-server+} v3.6. The minimum supported {+mdb-server+}
113113
version is now v4.0.
114-
115-
- The minimum wire version is now 7. See :manual:`minWireVersion </reference/command/hello/#mongodb-data-hello.minWireVersion>`.
114+
- Deprecates support for {+mdb-server+} v4.0. In accordance with the `MongoDB
115+
Software Lifecycle Schedules
116+
<https://www.mongodb.com/legal/support-policy/lifecycles>`__, an upcoming
117+
minor version of {+driver-short+} will raise the minimum {+mdb-server+}
118+
version from 4.0 to 4.2.
119+
- Drops support for Python v3.8. The minimum supported Python version is
120+
now v3.9.
121+
- Drops support for PyPy v3.9. The minimum supported PyPy version is now
122+
v3.10.
123+
- Drops support for the ``MONGODB-CR`` authentication mechanism. For more
124+
information about authentication, see the :ref:`Authentication Mechanisms
125+
<pymongo-authentication-mechanisms>` guide.
116126

117127
.. _version-4.9-breaking-changes:
118128

source/whats-new.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ Learn what's new in:
2727

2828
.. _upcoming-breaking-changes:
2929

30+
Upcoming Breaking Changes
31+
-------------------------
32+
33+
In accordance with the `MongoDB Software Lifecycle Schedules
34+
<https://www.mongodb.com/legal/support-policy/lifecycles>`__, an upcoming minor
35+
version of {+driver-short+} will raise the minimum {+mdb-server+} version from
36+
4.0 to 4.2. {+driver-short+} will no longer support {+mdb-server+} 4.0. To learn
37+
how to upgrade your driver version, see the :ref:`pymongo-upgrade` guide.
38+
3039
.. _version-4.11:
3140

3241
What's New in 4.11
@@ -42,6 +51,25 @@ The {+driver-short+} v4.11 release includes the following new features:
4251
- Adds support for free-threaded CPython when running Python v3.13+.
4352
For more information about free threading, see the
4453
`Python documentation <https://docs.python.org/3/howto/free-threading-python.html>`__.
54+
- In-use encryption requires ``pymongocrypt`` v1.12 or later.
55+
- The ``MongoClient.address()`` and ``AsyncMongoClient.address()`` methods correctly block
56+
when called on unconnected clients.
57+
- Adds ``__repr__`` support for the ``IndexModel`` and ``SearchIndexModel`` classes.
58+
- Adds a ``sort`` parameter to the following methods:
59+
60+
- ``Collection.update_one()``
61+
- ``Collection.replace_one()``
62+
- ``operations.UpdateOne()``
63+
- ``operations.UpdateMany()``
64+
65+
- The ``MongoClient.bulkWrite()`` and ``AsyncMongoClient.bulk_write()`` methods throw an
66+
error error if you use them with unacknowledged writes when the
67+
``ordered`` or ``verboseResults`` options are set to ``True``.
68+
- Fixes a bug that caused ``DatetimeMS`` to be incorrectly encoded as
69+
``'{"$date": "X"}'`` instead of ``'{"$date": X}'`` when using the the legacy
70+
MongoDB Extended JSON datetime representation.
71+
- Fixes a bug that caused the ``bson.json_util.loads()`` method to raise an ``IndexError``
72+
instead of a ``ValueError`` when parsing an invalid ``$date`` value.
4573

4674
.. _version-4.10:
4775

0 commit comments

Comments
 (0)