Skip to content

MongoDB Go Driver 1.12.0

Compare
Choose a tag to compare
@matthewdale matthewdale released this 21 Jun 23:58
· 175 commits to master since this release
v1.12.0
e113d80

The MongoDB Go Driver Team is pleased to release version 1.12.0 of the official Go driver.

Release Notes

This release adds support for MongoDB 7.0, including production-ready support for Queryable Encryption. It also adds a new logging interface and configuration API improvements.

Production-Ready Queryable Encryption

This release introduces backwards breaking changes to the Queryable Encryption protocol. Using Queryable Encryption now requires MongoDB 7.0+ and libmongocrypt v1.8.0+.

It also adds the new ClientEncryption.CreateEncryptedCollection method to automatically create data encryption keys when creating a new encrypted collection and adds the ability to fetch KMS credentials automatically from Azure, GCP, and AWS environments.

Logging

This release introduces a logging interface to allow users to more easily record detailed information about connection management and command execution within their application.

The logging configuration adds a new LogSink interface that is compatible with the logr.LogSink interface, allowing users to use existing logr adapters, like zerologr or zapr. Users may also implement their own LogSink adapter.

For example, to integrate logging with an existing zerolog logger:

sink := zerologr.New(&myLogger).GetSink()
loggerOptions := options.Logger().SetSink(sink)
options.Client().SetLoggerOptions(loggerOptions)

Logging can also be enabled using environment variables. For example, to enable command logging at info level to client.log, set:

export MONGODB_LOG_COMMAND=info
export MONGODB_LOG_MAX_DOCUMENT_LENGTH=100
export MONGODB_LOG_PATH="client.log"

Convenient BSON Options

The options package has a new way to set various BSON marshaling and unmarshaling behaviors.

For example, to set BSON options that cause the Go driver to fallback to "json" struct tags if "bson" struct tags are missing, marshal nil Go maps as empty BSON documents, and marshals nil Go slices as empty BSON arrays, use the new options.BSONOptions configuration:

bsonOpts := &options.BSONOptions{
	UseJSONStructTags: true,
	NilMapAsEmpty:     true,
	NilSliceAsEmpty:   true,
}
options.Client().SetBSONOptions(bsonOpts)

Convenient Write Concerns

The writeconcern package has new convenience functions Majority, W1, Journaled, and Unacknowledged for creating common write concerns.

For example, to configure a Client to use write concern {w: 1}, use the new writeconcern.W1() function:

options.Client().SetWriteConcern(writeconcern.W1())

Additional Changes

  • Support authenticating with AWS IAM roles in EKS.
  • Add SetBatchSize to Cursor to allow specifying the size of batches fetched from the database when iterating a cursor. It is primarily intended for use with cursors returned by RunCommandCursor.
  • Add bson.UnmarshalValue to allow unmarshaling BSON values that were marshaled using the existing bson.MarshalValue.
  • Deprecate various APIs that will be replaced or removed in Go Driver v2.0.

For a full list of tickets included in this release, please see the links below:

Full Changelog: v1.11.7...1.12.0

Documentation for the Go driver can be found on pkg.go.dev and the MongoDB documentation site. BSON library documentation is also available on pkg.go.dev. Questions and inquiries can be asked on the MongoDB Developer Community. Bugs can be reported in the Go Driver project in the MongoDB JIRA where a list of current issues can be found. Your feedback on the Go driver is greatly appreciated!