For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

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 .NET/C# 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.

To enable compression for the connection to your MongoDB instance, specify the algorithms you want to use in one of the following ways:

  1. Add the algorithms to your connection string as a parameter

  2. Specify the algorithms in the Compressors property of your MongoClientSettings object

To enable compression by using the connection string, add the compressors parameter to the connection string. You can specify one or more compression algorithms, separating them with commas:

const string connectionUri = "mongodb+srv://<db_username>:<db_password>@<cluster-url>/?compressors=snappy,zlib,zstd"; var client = new MongoClient(connectionUri);
Rate this page