Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ toc_landing_pages = [
"/data-formats",
"/builders",
"/aggregation",
"/connect/connection-options"
]

sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"
Expand Down
30 changes: 1 addition & 29 deletions source/connect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Connection Guide

Create a MongoClient </connect/mongoclient>
Choose a Connection Target </connect/connection-targets>
Connection Options </connect/connection-options>
Connection Options </connect/connection-options>
AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>

.. /connect/connection-troubleshooting
Expand Down Expand Up @@ -124,34 +124,6 @@ connecting by using TLS:
.. To learn more about disabling hostname verification, see :ref:`kotlin-sync-insecure-tls` in
.. the TLS configuration guide.

Network Compression
-------------------

The following sections describe how to connect to MongoDB
while specifying network compression algorithms.

Compression Algorithms
~~~~~~~~~~~~~~~~~~~~~~

The following tabs demonstrate how to specify all available compressors
while connecting to MongoDB:

.. include:: /includes/connect/compression-tabs.rst

.. To learn more about specifying compression algorithms, see
.. :ref:`kotlin-sync-enable-compression` in the Network Compression guide.

zlib Compression Level
~~~~~~~~~~~~~~~~~~~~~~

The following tabs demonstrate how to specify a compression level for
the ``zlib`` compressor:

.. include:: /includes/connect/zlib-level-tabs.rst

.. To learn more about setting the zlib compression level, see
.. :ref:`kotlin-sync-enable-compression` in the Network Compression guide.

Server Selection
----------------

Expand Down
6 changes: 3 additions & 3 deletions source/connect/connection-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Specify Connection Options
:titlesonly:
:maxdepth: 1

Stable API </connect/stable-api>
Limit Server Execution Time </connect/csot>
Stable API </connect/connection-options/stable-api>
Limit Server Execution Time </connect/connection-options/csot>
Network Compression </connect/connection-options/network-compression>

.. /connect/network-compression
.. /connect/server-selection

Overview
Expand Down
File renamed without changes.
96 changes: 96 additions & 0 deletions source/connect/connection-options/network-compression.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.. _kotlin-sync-compression:

========================
Compress Network Traffic
========================

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: zlib, zstandard, zstd, snappy

Overview
--------

In this guide, you can learn how to use the {+driver-short+} to enable network
compression. The driver provides a connection option to compress messages, which
reduces the amount of data passed over the network between MongoDB and your application.

The driver supports the following compression algorithms:

- `Snappy <https://google.github.io/snappy/>`__
- `Zlib <https://zlib.net/>`__
- `Zstandard <https://github.com/facebook/zstd/>`__

If you specify multiple compression algorithms, the driver selects the first one
in the list supported by your MongoDB instance.

.. note::

Applications that require Snappy or Zstandard compression must
add explicit dependencies for those algorithms. To learn more,
see the :ref:`kotlin-sync-compression-dependencies` section of this guide.

Specify Compression Algorithms
------------------------------

You can enable compression for the connection to your MongoDB instance
by specifying the algorithms in one of the following ways:

- Chain the ``compressorList()`` method to the ``MongoClientSettings.builder()`` method.
- Use the ``compressors`` parameter in your connection URI.

The following examples demonstrate how to specify all available compressors
while connecting to MongoDB. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
tab to see the corresponding syntax:

.. include:: /includes/connect/compression-tabs.rst

Specify the Zlib Compression Level
----------------------------------

If you specify ``zlib`` as one of your compression algorithms, you can also use the
``MongoCompressor.LEVEL`` property to specify a compression level. This option accepts
an integer value between ``-1`` and ``9``:

- **-1:** Default compression (usually ``6``)
- **0:** No compression
- **1:** Fastest speed but lowest compression
- **9:** Best compression but slowest speed

The following examples demonstrate how to specify a compression level for
the ``zlib`` compressor. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
tab to see the corresponding syntax:

.. include:: /includes/connect/zlib-level-tabs.rst

.. _kotlin-sync-compression-dependencies:

Compression Algorithm Dependencies
----------------------------------

The JDK natively supports `Zlib <https://zlib.net/>`__ compression. However,
Snappy and Zstandard depend on open source Java implementations. To learn more
about these implementations, see the following GitHub repositories:

- `snappy-java <https://github.com/xerial/snappy-java>`__
- `zstd-jni <https://github.com/luben/zstd-jni>`__

API Documentation
-----------------

To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `MongoClient <{+driver-api+}/-mongo-client/index.html>`__
- `createSnappyCompressor() <{+core-api+}/MongoCompressor.html#createSnappyCompressor()>`__
- `createZlibCompressor() <{+core-api+}/MongoCompressor.html#createZlibCompressor()>`__
- `createZstdCompressor() <{+core-api+}/MongoCompressor.html#createZstdCompressor()>`__
Loading