Overview
The Ruby driver supports network compression to reduce the amount of data transmitted between the client and the server.
The driver supports the following compression algorithms:
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 yourMongo::Client
object
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.
uri = "mongodb://<hostname>:<port>/?compressors=zlib,snappy" client = Mongo::Client.new(uri)
To enable compression in your Client object, pass the compressors
option
to the Mongo::Client
constructor.
client = Mongo::Client.new(["<hostname>:<port>"], compressors: ["zlib", "snappy"])