Skip to content

Commit 6118893

Browse files
DOCSP-51416 Network Compression (#162)
1 parent ff9a0e8 commit 6118893

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name = "ruby-driver"
22
title = "Ruby Driver"
33
toc_landing_pages = [
4+
"/connect/connection-options",
45
"/crud/query",
56
"/indexes",
67
"/security/authentication"

source/connect.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ Connect to MongoDB
2323
:maxdepth: 1
2424

2525
Create a Client </connect/mongoclient>
26-
Stable API </connect/stable-api>
2726
Choose a Connection Target </connect/connection-targets>
2827
Connection Options </connect/connection-options>
29-
Configure TLS </connect/tls>
30-
Limit Server Execution Time </connect/csot>
3128
AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>

source/connect/connection-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Specify Connection Options
1717
.. meta::
1818
:keywords: connection string, URI, server, Atlas, settings, configure
1919

20+
.. toctree::
21+
:titlesonly:
22+
:maxdepth: 1
23+
24+
Compress Network Traffic </connect/network-compression>
25+
Stable API </connect/stable-api>
26+
Limit Server Execution Time </connect/csot>
27+
2028
Overview
2129
--------
2230

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# start-connection-string
2+
uri = "mongodb://<hostname>:<port>/?compressors=zlib,snappy"
3+
client = Mongo::Client.new(uri)
4+
# end-connection-string
5+
6+
# start-client-settings
7+
client = Mongo::Client.new(["<hostname>:<port>"],
8+
compressors: ["zlib", "snappy"])
9+
# end-client-settings

0 commit comments

Comments
 (0)