Skip to content

Commit 5b70cf9

Browse files
GODRIVER-2955 Add user-facing network compression documentation (#1402)
1 parent 6d73aa1 commit 5b70cf9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ if err == mongo.ErrNoDocuments {
148148

149149
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/).
150150

151+
### Network Compression
152+
153+
Network compression will reduce bandwidth requirements between MongoDB and the application.
154+
155+
The Go Driver supports the following compression algorithms:
156+
157+
1. [Snappy](https://google.github.io/snappy/) (`snappy`): available in MongoDB 3.4 and later.
158+
2. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
159+
3. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.
160+
161+
#### Specify Compression Algorithms
162+
163+
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):
164+
165+
```
166+
opts := options.Client().ApplyURI("mongodb://localhost:27017/?compressors=snappy,zlib,zstd")
167+
client, _ := mongo.Connect(context.TODO(), opts)
168+
```
169+
170+
```
171+
opts := options.Client().SetCompressors([]string{"snappy", "zlib", "zstd"})
172+
client, _ := mongo.Connect(context.TODO(), opts)
173+
```
174+
175+
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).
176+
177+
Messages compress when both parties enable network compression; otherwise, messages remain uncompressed
178+
151179
-------------------------
152180
## Feedback
153181

mongo/options/clientoptions.go

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

0 commit comments

Comments
 (0)