|
| 1 | +======================== |
| 2 | +Compress Network Traffic |
| 3 | +======================== |
| 4 | + |
| 5 | +.. meta:: |
| 6 | + :keywords: network compression, zlib, snappy, zstd, Ruby driver, connection string, URI, settings, configure |
| 7 | + |
| 8 | +.. contents:: On this page |
| 9 | + :local: |
| 10 | + :depth: 2 |
| 11 | + |
| 12 | +Overview |
| 13 | +-------- |
| 14 | + |
| 15 | +The {+driver-short+} supports network compression to reduce the amount |
| 16 | +of data transmitted between the client and the server. |
| 17 | + |
| 18 | +The driver supports the following compression algorithms: |
| 19 | + |
| 20 | +- `Snappy <https://google.github.io/snappy/>`__ |
| 21 | +- `Zlib <https://zlib.net/>`__ |
| 22 | +- `Zstandard <https://github.com/facebook/zstd/>`__ |
| 23 | + |
| 24 | + |
| 25 | +If you specify multiple compression algorithms, the driver selects the first |
| 26 | +one in the list supported by your MongoDB instance. |
| 27 | + |
| 28 | +Specify Compression Algorithms |
| 29 | +------------------------------ |
| 30 | + |
| 31 | +To enable compression for the connection to your MongoDB instance, |
| 32 | +specify the algorithms you want to use in one of the following ways: |
| 33 | + |
| 34 | +- Add the algorithms to your connection string as a parameter |
| 35 | +- Specify the algorithms in the ``compressors`` option of your ``Mongo::Client`` object |
| 36 | + |
| 37 | +.. tabs:: |
| 38 | + |
| 39 | + .. tab:: Connection String |
| 40 | + :tabid: connection-string |
| 41 | + |
| 42 | + To enable network compression by using the connection string, add the ``compressors`` option. |
| 43 | + You can specify one or more algorithms as a comma-separated list. |
| 44 | + |
| 45 | + .. literalinclude:: /includes/connect/network-compression.rb |
| 46 | + :start-after: start-connection-string |
| 47 | + :end-before: end-connection-string |
| 48 | + :language: ruby |
| 49 | + |
| 50 | + .. tab:: Client Settings |
| 51 | + :tabid: client-settings |
| 52 | + |
| 53 | + To enable compression in your Client object, pass the ``compressors`` option |
| 54 | + to the ``Mongo::Client`` constructor. |
| 55 | + |
| 56 | + .. literalinclude:: /includes/connect/network-compression.rb |
| 57 | + :start-after: start-client-settings |
| 58 | + :end-before: end-client-settings |
| 59 | + :language: ruby |
0 commit comments