Docs Menu

Docs HomeDevelop ApplicationsMongoDB DriversKotlin Coroutine

Network Compression

On this page

  • Specify Compression Algorithms
  • Compression Algorithm Dependencies

The MongoDB Kotlin Driver provides a connection option to compress messages, This reduces the amount of data passed over the network between MongoDB and your application.

The driver supports the following algorithms:

  1. Snappy: available in MongoDB 3.4 and later.

  2. Zlib: available in MongoDB 3.6 and later.

  3. Zstandard: available in MongoDB 4.2 and later.

The driver tests against the following versions of these libraries:

  • org.xerial.snappy:snappy-java:1.1.8.4

  • com.github.luben:zstd-jni:1.5.5-2

If you specify multiple compression algorithms, the driver selects the first one that is supported by the MongoDB instance that the driver is connected to.

Note

If your application requires Snappy or Zstandard compression, you must add explicit dependencies for those algorithms.

You can enable compression on your connection by specifying the algorithms in the following ways:

  • Adding the compressors parameter to your ConnectionString instance

  • Calling the compressorList() method from the MongoClientSettings builder

The JDK supports Zlib compression natively, but Snappy and Zstandard depend on open source implementations. See snappy-java and zstd-java for details.

←  Specify MongoClient SettingsEnable TLS/SSL on a Connection →