Docs Menu
Docs Home
/ / /
Go Driver

What's New

On this page

  • What's New in 2.0
  • What's New in 1.17
  • What's New in 1.16
  • What's New in 1.15.1
  • What's New in 1.15
  • What's New in 1.14
  • What's New in 1.13
  • What's New in 1.12.1
  • What's New in 1.12

Tip

Release Notes

To learn more about changes and updates between versions, you can read the release notes published with the driver source code.

Learn what's new in:

The 2.0 Go driver release supports OpenID Connect (OIDC) authentication, provides a smoother client-side operations timeout (CSOT) experience, and implements clearer, more idiomatic Go code by streamlining APIs, improving errors descriptions, and simplifying the driver package structure.

You can learn more about these changes in this section, or by viewing the v2.0 Migration Guide in the Go driver source code on GitHub.

Important

Breaking Changes

The Go driver v2.0 release introduces the following breaking changes:

  • mongo.Connect() does not accept a Context parameter. This method accepts only an options object. To view an example that uses this method, see the Connection Example Code in the Connection Guide.

  • The Cursor.SetMaxTime() method is renamed to Cursor.SetMaxAwaitTime(). This method specifies the maximum time that the server waits for new documents retrieved from a capped collection with a tailable cursor.

  • Removal of operation-specific timeout options. The following fields and setter methods have been removed from the driver:

    • AggregateOptions.MaxTime, AggregateOptions.SetMaxTime()

    • ClientOptions.SocketTimeout, ClientOptions.SetSocketTimeout()

    • CountOptions.MaxTime, CountOptions.SetMaxTime()

    • DistinctOptions.MaxTime, DistinctOptions.SetMaxTime()

    • EstimatedDocumentCountOptions.MaxTime, EstimatedDocumentCountOptions.SetMaxTime()

    • FindOptions.MaxTime, FindOptions.SetMaxTime()

    • FindOneOptions.MaxTime, FindOneOptions.SetMaxTime()

    • FindOneAndReplaceOptions.MaxTime, FindOneAndReplaceOptions.SetMaxTime()

    • FindOneAndUpdateOptions.MaxTime, FindOneAndUpdateOptions.SetMaxTime()

    • GridFSFindOptions.MaxTime, GridFSFindOptions.SetMaxTime()

    • CreateIndexesOptions.MaxTime, CreateIndexesOptions.SetMaxTime()

    • DropIndexesOptions.MaxTime, DropIndexesOptions.SetMaxTime()

    • ListIndexesOptions.MaxTime, ListIndexesOptions.SetMaxTime()

    • SessionOptions.DefaultMaxCommitTime, SessionOptions.SetDefaultMaxCommitTime()

    • TransactionOptions.MaxCommitTime, TransactionOptions.SetMaxCommitTime()

    • WriteConcern.WTimeout

    Instead, you can set a timeout on your client or within a Context. Learn more in the Single Timeout Setting section of the Connection Options guide.

This release includes the following improvements and fixes:

  • Support for OpenID Connect (OIDC) authentication. To learn more, see the MONGODB-OIDC section of the Enterprise Authentication Mechanisms guide.

  • You can access the GridFS API from the mongo package. In previous versions, you could access GridFS functions from the separate gridfs package, but this functionality is now merged with the main driver mongo package. To learn more, see the GridFS guide.

  • The Comment field in any options struct takes a value of type any instead of type string. To set this field, you can use the SetComment() method and pass a parameter of type any.

  • Updates to monitoring event documents:

    • The CommandStartedEvent and CommandFinishedEvent structs have a single ServerConnectionID field of type int64 to capture the connection ID.

    • The ConnectionID field of the PoolEvent struct takes a value of type int64 instead of uint64.

    To view sample event documents, see the Monitoring guides.

  • The Session interface is converted to a struct. See the Transactions guide to learn more.

  • The Distinct() method returns a struct that can be decoded into a specified type. See the Retrieve Distinct Values guide to learn more.

  • The IndexView.DropOne() method returns only an error, if present. In previous versions, this method also returned the server response, which contained the number of dropped indexes. See the Remove an Index section of the Indexes guide to learn more.

  • Updates to the builder pattern for types in the options package. The pattern maintains a slice of setter functions, so you cannot set data directly to an options object. This update does not generally change how you create and use options. To learn more, see the feature JIRA ticket.

  • The driver no longer supports the mongo.ErrUnacknowledgedWrite sentinel error if a write operation is not acknowledged. To confirm that the server acknowledged a write operation, you must access the Acknowledged property from the result struct returned by the write method.

    The following example shows how to confirm acknowledgment of an insert operation:

    res, err := coll.InsertOne(context.TODO(), bson.D{{"x", 2}})
    if err != nil {
    panic(err)
    }
    fmt.Print(res.Acknowledged)
  • You can set options for transactions run in a given session by creating a TransactionOptions instance and passing the instance to the SetDefaultTransactionOptions() method of the SessionOptions type. To learn more, see the Session and Transaction Options section of the Transactions guide.

  • The Collection.Clone() method does not return an error.

  • Renames the canonical parameter of the UnmarshalExtJSON() method to canonicalOnly. If you set canonicalOnly to true, the method returns an error if the extended JSON is not marshaled in canonical mode. If set to false, the method can unmarshal canonical or relaxed extended JSON. To learn more, see the UnmarshalExtJSON() API documentation.

Important

v1.17 is the final planned 1.x version release. This version will receive security and bug fixes, but future development and features will be included only in 2.x versions of the driver.

The 1.17 Go driver release includes the following improvements and fixes:

  • Adds support for OpenID Connect (OIDC) authentication. To learn more, see the MONGODB-OIDC section of the Enterprise Authentication Mechanisms guide.

  • Adds support for Queryable Encryption (QE) range queries. To use this feature, your app must connect to MongoDB Server 8.0 or later. For more information about QE range queries, see Queryable Encryption in the MongoDB Server manual.

  • Adds support for MongoDB Server 8.0, except for the client bulk write feature.

  • Extends the IndexView type to include the DropOneWithKey() and DropWithKey() methods so you can drop indexes by using their key specifications instead of their names.

For more information about the changes in this version, see the v1.17 release notes on GitHub.

The 1.16 Go driver release includes the following improvements and fixes:

  • Adds support for specifying an index type when creating an Atlas Search index.

  • Reduces memory usage when the zstd compression algorithm is enabled.

  • Upgrades some dependency requirements. For a list of upgrades, see the "Upgrade Dependencies" section of the v1.16 release notes.

For more information about these changes, see the v1.16 release notes on Github.

The 1.15.1 Go driver patch release includes the following improvements and fixes:

  • Fixes a possible connection leak where disconnecting from a replica set cluster left behind rttMonitor connections.

  • Adds support for manually specifying a maxTimeMS value for read and aggregation operations when a client-wide timeout and an operation timeout are set.

  • Adds a RemainingBatchLength() method that you can call on a change stream.

For more information about these changes, see the v1.15.1 release notes on Github.

The 1.15 Go driver release includes the following improvements and fixes:

  • Connection churn can be mitigated by setting a client-wide timeout by specifying the timeoutMS connection option or by calling the SetTimeout() function. When the timeout is set, the driver attempts to reuse a connection after an operation times out and waits for up to one second to check if the connection can be reused before closing it.

  • Connection pool events include a Duration field to measure the checkout duration and total amount of time it took to establish a connection.

The 1.14 Go driver release includes the following improvements and fixes:

  • Go versions before 1.18 are no longer supported.

  • In case of a heartbeat timeout, in-progress operations are preemptively canceled.

  • Connection strings that include the "mongodb+srv://" prefix can contain capital letters in the SRV hostname.

The 1.13 Go driver release includes the following improvements and fixes:

  • Logging for server selection and SDAM. To learn more about logging, see the Logging documentation.

  • Methods on the Collection type that allow you to manage search indexes programmatically.

  • The event.CommandStartedEvent and event.CommandFinishedEvent events return the DatabaseName field. This field is also included in the command-logging analogs.

  • In a sharded topology, when selecting a server to retry an unsuccessful query, the driver excludes the server used for the initial attempt. Instead, if there's more than one eligible mongos instance, the driver randomly selects one. Unhealthy instances are automatically excluded from selection.

  • Streaming SDAM is disabled by default on AWS Lambda and similar function-as-a-service (FaaS) platforms. You can enable monitoring by using the serverMonitoringMode URI option.

The 1.12 Go driver release includes the following improvements and fixes:

  • The driver unpins connections when ending a session. This prevents connections from leaking when a user runs a transaction while connected to a load balancer.

  • The driver does not throw a runtime error when you unmarshal an empty bson.RawValue type with an invalid type or marshal a nil pointer of a ReadConcern instance.

  • Setting options.LogComponentAll as the log component correctly results in the publication of logs against all components.

Important

Deprecation Notice

  • The mongo.NewClient() and client.Connect() methods are deprecated. You can create a client and connect in one call by using the mongo.Connect() method.

New features of the 1.12 Go driver release include:

This driver version adds support for Queryable Encryption (QE). To learn more about the requirements for using the QE feature, see the Queryable Encryption Driver Compatibility Table.

The ClientEncryption.CreateEncryptedCollection() method automatically creates data encryption keys when you create a new encrypted collection. To learn how to use the QE feature, see the Quick Start in the Server manual.

You can now record connection management and command execution events by using the LogSink logging interface.

To learn more, see the Logging Fundamentals guide.

This driver version adds features to the options package to specify how the driver marshals and unmarshals BSON.

The following example shows how to set BSON options on your Client. The options specify the following behaviors:

  • The driver falls back to json struct tags if bson struct tags are absent.

  • The driver marshals nil Go map types as empty BSON documents.

  • The driver marshals nil Go slice types as empty BSON arrays.

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

For a full example of how to specify and implement the BSONOptions type, see the API documentation.

This driver version simplifies the WriteConcern API. To learn more about the changes, see Write Concern.

  • Support for authentication with AWS IAM roles in EKS.

  • Addition of the Cursor.SetBatchSize() method to allow specification of the size of batches fetched when iterating through a cursor.

  • Addition of the UnmarshalValue() method to allow ummarshalling of BSON values marshalled with the MarshalValue() method.

Back

Quick Reference