diff --git a/snooty.toml b/snooty.toml index 7d7ee58b..d2e2e4a1 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,6 +1,7 @@ name = "ruby-driver" title = "Ruby Driver" toc_landing_pages = [ + "/connect/connection-options", "/crud/query", "/indexes", "/security/authentication" diff --git a/source/connect.txt b/source/connect.txt index 22eeab0b..6d64baec 100644 --- a/source/connect.txt +++ b/source/connect.txt @@ -23,9 +23,6 @@ Connect to MongoDB :maxdepth: 1 Create a Client - Stable API Choose a Connection Target Connection Options - Configure TLS - Limit Server Execution Time AWS Lambda diff --git a/source/connect/connection-options.txt b/source/connect/connection-options.txt index 769ff176..b39c9c8a 100644 --- a/source/connect/connection-options.txt +++ b/source/connect/connection-options.txt @@ -17,6 +17,14 @@ Specify Connection Options .. meta:: :keywords: connection string, URI, server, Atlas, settings, configure +.. toctree:: + :titlesonly: + :maxdepth: 1 + + Compress Network Traffic + Stable API + Limit Server Execution Time + Overview -------- diff --git a/source/connect/network-compression.txt b/source/connect/network-compression.txt new file mode 100644 index 00000000..b1901893 --- /dev/null +++ b/source/connect/network-compression.txt @@ -0,0 +1,59 @@ +======================== +Compress Network Traffic +======================== + +.. meta:: + :keywords: network compression, zlib, snappy, zstd, Ruby driver, connection string, URI, settings, configure + +.. contents:: On this page + :local: + :depth: 2 + +Overview +-------- + +The {+driver-short+} supports network compression to reduce the amount +of data transmitted between the client and the server. + +The driver supports the following compression algorithms: + +- `Snappy `__ +- `Zlib `__ +- `Zstandard `__ + + +If you specify multiple compression algorithms, the driver selects the first +one in the list supported by your MongoDB instance. + +Specify Compression Algorithms +------------------------------ + +To enable compression for the connection to your MongoDB instance, +specify the algorithms you want to use in one of the following ways: + +- Add the algorithms to your connection string as a parameter +- Specify the algorithms in the ``compressors`` option of your ``Mongo::Client`` object + +.. tabs:: + + .. tab:: Connection String + :tabid: connection-string + + To enable network compression by using the connection string, add the ``compressors`` option. + You can specify one or more algorithms as a comma-separated list. + + .. literalinclude:: /includes/connect/network-compression.rb + :start-after: start-connection-string + :end-before: end-connection-string + :language: ruby + + .. tab:: Client Settings + :tabid: client-settings + + To enable compression in your Client object, pass the ``compressors`` option + to the ``Mongo::Client`` constructor. + + .. literalinclude:: /includes/connect/network-compression.rb + :start-after: start-client-settings + :end-before: end-client-settings + :language: ruby diff --git a/source/includes/connect/network-compression.rb b/source/includes/connect/network-compression.rb new file mode 100644 index 00000000..65281115 --- /dev/null +++ b/source/includes/connect/network-compression.rb @@ -0,0 +1,9 @@ +# start-connection-string +uri = "mongodb://:/?compressors=zlib,snappy" +client = Mongo::Client.new(uri) +# end-connection-string + +# start-client-settings +client = Mongo::Client.new([":"], + compressors: ["zlib", "snappy"]) +# end-client-settings \ No newline at end of file