From 1bb506f7877de5c1cd0efef557dcf3569cfb9aa9 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 29 Jan 2025 13:46:38 -0500 Subject: [PATCH 1/6] DOCSP-46690: Compression --- source/connect.txt | 1 + source/connect/compression.txt | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 source/connect/compression.txt diff --git a/source/connect.txt b/source/connect.txt index 6c983b01..526a3aae 100644 --- a/source/connect.txt +++ b/source/connect.txt @@ -30,6 +30,7 @@ Connect to MongoDB Customize Server Selection Stable API Limit Server Execution Time + Compression Overview -------- diff --git a/source/connect/compression.txt b/source/connect/compression.txt new file mode 100644 index 00000000..235c9eb4 --- /dev/null +++ b/source/connect/compression.txt @@ -0,0 +1,80 @@ +.. _pymongo-compression: + +=========== +Compression +=========== + +.. facet:: + :name: genre + :values: reference + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +In this guide, you can learn how to use supported compression algorithms with +{+driver-short+}. + +You can use compression to reduce the size of messages sent between your application +and a MongoDB deployment. {+driver-short+} supports the following compression algorithms: + +- `Snappy `__: You can use Snappy compression + with MongoDB 3.4 and later by including the `python-snappy `__ + package in your application. +- `Zlib `__: You can use Zlib compression with MongoDB 3.6 and later. +- `Zstandard `__: You can use Zstandard compression + with MongoDB 4.2 and later by including the `zstandard `__ + package in your application. + +Specifying Compression By Using a Connection String +--------------------------------------------------- + +You can specify the compression algorithm to use by including the ``compressors`` option +in yoru connection string. The following example specifies the Snappy compression algorithm + +.. code-block:: python + + client = pymongo.MongoClient("mongodb://localhost/?compressors=snappy") + +You can also specify multiple compression algorithms by separating them with a comma, as +show in the following example: + +.. code-block:: python + + client = pymongo.MongoClient("mongodb://localhost/?compressors=snappy,zlib,zstd") + +Specifying Compression to a MongoClient +--------------------------------------- + +You can also specify the compression algorithm to use when creating a ``MongoClient`` object, +as shown in the following example: + +.. code-block:: python + + client = pymongo.MongoClient(compressors="snappy") + +You can also specify multiple compression algorithms by passing a list of algorithms to the +``MongoClient`` constructors, as shown in the following example: + +.. code-block:: python + + client = pymongo.MongoClient(compressors=["snappy", "zlib", "zstd"]) + +.. note:: + + When you supply multiple compression algorithms to a ``MongoClient``, + {+driver-short+} uses the first compression algorithm in the list that the + deployment supports. + +API Documentation +----------------- + +To learn more about any of the methods or types discussed in this +guide, see the following API documentation: + +- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__ \ No newline at end of file From aab1adb942a6d0eb60716e88b930f74f3b8b1d53 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 29 Jan 2025 13:47:55 -0500 Subject: [PATCH 2/6] Fix --- source/connect/compression.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connect/compression.txt b/source/connect/compression.txt index 235c9eb4..18446cb4 100644 --- a/source/connect/compression.txt +++ b/source/connect/compression.txt @@ -35,7 +35,7 @@ Specifying Compression By Using a Connection String --------------------------------------------------- You can specify the compression algorithm to use by including the ``compressors`` option -in yoru connection string. The following example specifies the Snappy compression algorithm +in your connection string. The following example specifies the Snappy compression algorithm .. code-block:: python From 5fd439f457a39d667ee55060b0f087d6356bba3d Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 29 Jan 2025 13:55:01 -0500 Subject: [PATCH 3/6] Fixes --- source/connect/compression.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/connect/compression.txt b/source/connect/compression.txt index 18446cb4..766abbf4 100644 --- a/source/connect/compression.txt +++ b/source/connect/compression.txt @@ -17,7 +17,7 @@ Compression Overview -------- -In this guide, you can learn how to use supported compression algorithms with +In this guide, you can learn how to use compression algorithms with {+driver-short+}. You can use compression to reduce the size of messages sent between your application @@ -51,15 +51,16 @@ show in the following example: Specifying Compression to a MongoClient --------------------------------------- -You can also specify the compression algorithm to use when creating a ``MongoClient`` object, -as shown in the following example: +You can also specify the compression algorithm to use by passing the algorithms to use +to the ``compressors`` parameter of the ``MongoClient`` constructor, as shown in the +following example: .. code-block:: python client = pymongo.MongoClient(compressors="snappy") You can also specify multiple compression algorithms by passing a list of algorithms to the -``MongoClient`` constructors, as shown in the following example: +``MongoClient`` constructor, as shown in the following example: .. code-block:: python From 223e6638828b09c71dd2457915ca5ae0a95e197c Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 29 Jan 2025 14:22:13 -0500 Subject: [PATCH 4/6] RM feedback --- source/connect/compression.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/connect/compression.txt b/source/connect/compression.txt index 766abbf4..2e38a053 100644 --- a/source/connect/compression.txt +++ b/source/connect/compression.txt @@ -48,6 +48,12 @@ show in the following example: client = pymongo.MongoClient("mongodb://localhost/?compressors=snappy,zlib,zstd") +.. note:: + + When you supply multiple compression algorithms to a connection string, + {+driver-short+} uses the first compression algorithm in the list that the + deployment supports. + Specifying Compression to a MongoClient --------------------------------------- From 18969a32cfc0488d23bd94373ffc95d677462f4c Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 31 Jan 2025 14:28:18 -0500 Subject: [PATCH 5/6] Technical feedback --- source/connect/compression.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/connect/compression.txt b/source/connect/compression.txt index 2e38a053..c47a7952 100644 --- a/source/connect/compression.txt +++ b/source/connect/compression.txt @@ -26,7 +26,9 @@ and a MongoDB deployment. {+driver-short+} supports the following compression al - `Snappy `__: You can use Snappy compression with MongoDB 3.4 and later by including the `python-snappy `__ package in your application. -- `Zlib `__: You can use Zlib compression with MongoDB 3.6 and later. +- `Zlib `__: You can use Zlib compression with MongoDB 3.6 and later by + by including the `zlib `__ package + in your application. - `Zstandard `__: You can use Zstandard compression with MongoDB 4.2 and later by including the `zstandard `__ package in your application. From 4fab5a76ac847c0b977ee6da97338596094d99ff Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 31 Jan 2025 14:28:42 -0500 Subject: [PATCH 6/6] Fix --- source/connect/compression.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connect/compression.txt b/source/connect/compression.txt index c47a7952..55946c83 100644 --- a/source/connect/compression.txt +++ b/source/connect/compression.txt @@ -26,7 +26,7 @@ and a MongoDB deployment. {+driver-short+} supports the following compression al - `Snappy `__: You can use Snappy compression with MongoDB 3.4 and later by including the `python-snappy `__ package in your application. -- `Zlib `__: You can use Zlib compression with MongoDB 3.6 and later by +- `Zlib `__: You can use Zlib compression with MongoDB 3.6 and later by including the `zlib `__ package in your application. - `Zstandard `__: You can use Zstandard compression