Skip to content

Commit

Permalink
GODRIVER-2955 Add user-facing network compression documentation (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez authored Sep 26, 2023
1 parent 6d73aa1 commit 5b70cf9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ if err == mongo.ErrNoDocuments {

Additional examples and documentation can be found under the examples directory and [on the MongoDB Documentation website](https://www.mongodb.com/docs/drivers/go/current/).

### Network Compression

Network compression will reduce bandwidth requirements between MongoDB and the application.

The Go Driver supports the following compression algorithms:

1. [Snappy](https://google.github.io/snappy/) (`snappy`): available in MongoDB 3.4 and later.
2. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
3. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.

#### Specify Compression Algorithms

Compression can be enabled using the `compressors` parameter on the connection string or by using [`ClientOptions.SetCompressors`](https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options#ClientOptions.SetCompressors):

```
opts := options.Client().ApplyURI("mongodb://localhost:27017/?compressors=snappy,zlib,zstd")
client, _ := mongo.Connect(context.TODO(), opts)
```

```
opts := options.Client().SetCompressors([]string{"snappy", "zlib", "zstd"})
client, _ := mongo.Connect(context.TODO(), opts)
```

If compressors are set, the Go Driver negotiates with the server to select the first common compressor. For server configuration and defaults, refer to [`networkMessageCompressors`](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--networkMessageCompressors).

Messages compress when both parties enable network compression; otherwise, messages remain uncompressed

-------------------------
## Feedback

Expand Down
2 changes: 1 addition & 1 deletion mongo/options/clientoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func (c *ClientOptions) SetAuth(auth Credential) *ClientOptions {
// 3. "zstd" - requires server version >= 4.2, and driver version >= 1.2.0 with cgo support enabled or driver
// version >= 1.3.0 without cgo.
//
// If this option is specified, the driver will perform a negotiation with the server to determine a common list of of
// If this option is specified, the driver will perform a negotiation with the server to determine a common list of
// compressors and will use the first one in that list when performing operations. See
// https://www.mongodb.com/docs/manual/reference/program/mongod/#cmdoption-mongod-networkmessagecompressors for more
// information about configuring compression on the server and the server-side defaults.
Expand Down

0 comments on commit 5b70cf9

Please sign in to comment.