|
1 | 1 | .. uses network-compression.rst, installation.rst
|
2 | 2 |
|
3 | 3 | .. _network-compression-example:
|
| 4 | +.. _pymongo-network-compression: |
4 | 5 |
|
| 6 | +=================== |
5 | 7 | Network Compression
|
6 | 8 | ===================
|
7 | 9 |
|
8 |
| -PyMongo supports network compression where network traffic between the client |
9 |
| -and MongoDB server are compressed which reduces the amount of data passed |
10 |
| -over the network. By default no compression is used. |
| 10 | +.. contents:: On this page |
| 11 | + :local: |
| 12 | + :backlinks: none |
| 13 | + :depth: 1 |
| 14 | + :class: singlecol |
| 15 | + |
| 16 | +.. facet:: |
| 17 | + :name: genre |
| 18 | + :values: reference |
| 19 | + |
| 20 | +.. meta:: |
| 21 | + :keywords: wire protocol |
| 22 | + |
| 23 | +{+driver-short+} supports network compression, which compresses network traffic |
| 24 | +between the client and the MongoDB server, and reduces the amount of data passed |
| 25 | +over the network. By default, {+driver-short+} doesn't use any compression. |
11 | 26 |
|
12 | 27 | The driver supports the following algorithms:
|
13 | 28 |
|
14 |
| -- `snappy <https://pypi.org/project/python-snappy>`_ available in MongoDB 3.4 and later. |
| 29 | +- `snappy <https://pypi.org/project/python-snappy>`__, available in MongoDB 3.4 and later. |
15 | 30 | - ``zlib`` available in MongoDB 3.6 and later.
|
16 |
| -- `zstandard <https://pypi.org/project/zstandard/>`_ available in MongoDB 4.2 and later. |
| 31 | +- `zstandard <https://pypi.org/project/zstandard/>`__, available in MongoDB 4.2 and later. |
17 | 32 |
|
18 | 33 | Wire protocol compression with snappy requires `python-snappy
|
19 |
| -<https://pypi.org/project/python-snappy>`_: |
| 34 | +<https://pypi.org/project/python-snappy>`__: |
20 | 35 |
|
21 | 36 | .. code-block:: python
|
22 | 37 |
|
23 |
| - $ python3 -m pip install "pymongo[snappy]" |
| 38 | + $ python3 -m pip install "pymongo[snappy]" |
24 | 39 |
|
25 | 40 | Wire protocol compression with zstandard requires `zstandard
|
26 |
| -<https://pypi.org/project/zstandard>`_: |
| 41 | +<https://pypi.org/project/zstandard>`__: |
27 | 42 |
|
28 | 43 | .. code-block:: python
|
29 | 44 |
|
30 |
| - $ python3 -m pip install "pymongo[zstd]" |
| 45 | + $ python3 -m pip install "pymongo[zstd]" |
| 46 | + |
| 47 | +Specify Compression Algorithms |
| 48 | +------------------------------ |
31 | 49 |
|
32 |
| -Applications can enable wire protocol compression via the ``compressors`` URI and |
33 |
| -keyword argument to the ``~pymongo.mongo_client.MongoClient`` method. For example: |
| 50 | +You can enable wire protocol compression when you're instantiating a |
| 51 | +``MongoClient`` by specifying the algorithm name in |
| 52 | +the ``compressors`` option. For example: |
34 | 53 |
|
35 | 54 | .. code-block:: python
|
36 | 55 |
|
37 | 56 | >>> client = MongoClient(compressors='zlib')
|
38 | 57 |
|
39 |
| -When multiple compression algorithms are given, the driver selects the first one in the |
40 |
| -list supported by the MongoDB instance to which it is connected. For example: |
| 58 | +When you specify multiple compression algorithms, the driver selects the first one in the |
| 59 | +list supported by the MongoDB instance it's connected to. For example: |
41 | 60 |
|
42 | 61 | .. code-block:: python
|
43 | 62 |
|
44 |
| - >>> client = MongoClient(compressors='snappy,zstandard,zlib') |
| 63 | + >>> client = MongoClient(compressors='snappy,zstandard,zlib') |
45 | 64 |
|
46 |
| -The ``compressors`` option can also be set via the URI: |
| 65 | +You can also set the ``compressors`` option in the connection URI: |
47 | 66 |
|
48 | 67 | .. code-block:: python
|
49 | 68 |
|
50 |
| - >>> client = MongoClient('mongodb://example.com/?compressors=snappy,zstandard,zlib') |
| 69 | + >>> client = MongoClient('mongodb://example.com/?compressors=snappy,zstandard,zlib') |
51 | 70 |
|
52 |
| -Additionally, zlib compression allows specifying a compression level with supported values from -1 to 9: |
| 71 | +Additionally, ``zlib`` compression allows specifying a compression level with supported values from -1 to 9: |
53 | 72 |
|
54 | 73 | .. code-block:: python
|
55 | 74 |
|
56 |
| - >>> client = MongoClient(compressors='zlib', zlibCompressionLevel=-1) |
| 75 | + >>> client = MongoClient(compressors='zlib', zlibCompressionLevel=-1) |
| 76 | + |
| 77 | +Pass the ``zlibCompressionLevel`` as the ``level`` argument to ``zlib.compress``. |
57 | 78 |
|
58 |
| -The ``zlibCompressionLevel`` is passed as the ``level`` argument to ``zlib.compress``. |
| 79 | +.. seealso:: |
59 | 80 |
|
60 |
| -.. seealso:: The MongoDB documentation on `network compression URI options <https://dochub.mongodb.org/core/compression-options>`_. |
| 81 | + To learn more about network compression URI options, see the |
| 82 | + :manual:`Compression Options </reference/connection-string/#compression-options>` |
| 83 | + section on the Server manual. |
0 commit comments