Docs Menu

Docs HomeNode.js

Network Compression

You can enable a driver option to compress messages, which reduces the amount of data passed over the network between MongoDB and your application.

The driver supports the following compression algorithms:

  1. Snappy: available in MongoDB 3.6 and later.

  2. Zlib: available in MongoDB 3.6 and later.

If you specify multiple compression algorithms, the driver selects the first one in the list supported by your MongoDB instance.

To enable compression for the connection to your MongoDB instance, use one of the following methods to specify the algorithms:

  1. Add the parameter to the connection string.

  2. Specify the compressors option in your MongoClientOptions.

Select the tab that matches your use case for instructions on how to specify the compression algorithm:

Specify compression algorithms by using the following strings:

  • "snappy" for Snappy compression

  • "zlib" for Zlib compression

To use Snappy compression, add it to your application dependencies by running the following command:

npm install --save snappy

You can use Zlib compression without adding any additional dependencies.

←  Connection OptionsEnable TLS on a Connection →
Share Feedback
© 2023 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.