-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-46690: Compression #158
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.. _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 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 <https://google.github.io/snappy/>`__: You can use Snappy compression | ||
with MongoDB 3.4 and later by including the `python-snappy <https://pypi.org/project/python-snappy/>`__ | ||
package in your application. | ||
- `Zlib <https://zlib.net/>`__: You can use Zlib compression with MongoDB 3.6 and later. | ||
- `Zstandard <https://github.com/facebook/zstd/>`__: You can use Zstandard compression | ||
with MongoDB 4.2 and later by including the `zstandard <https://pypi.org/project/zstandard/>`__ | ||
package in your application. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the tech reviewer: Does MongoDB have a recommendation for which method we prefer? If so, we should include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe snappy and zstd are considered faster than zlib but we have never actually benchmarked it in Python so I can't give a recommendation. |
||
|
||
Specifying Compression By Using a Connection String | ||
--------------------------------------------------- | ||
|
||
You can specify the compression algorithm to use by including the ``compressors`` option | ||
in your 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 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`` constructor, 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. | ||
mcmorisi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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>`__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's link to https://docs.python.org/3/library/zlib.html.