-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
.. _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 | ||
by including the `zlib <https://docs.python.org/3/library/zlib.html>`__ package | ||
in your application. | ||
- `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. | ||
|
||
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") | ||
|
||
.. 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 | ||
--------------------------------------- | ||
|
||
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. | ||
|
||
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>`__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.