Overview
This page describes the changes you must make to your application when you upgrade to a new version of the Go driver.
Before you upgrade, perform the following actions:
Ensure the new Go driver version is compatible with the MongoDB Server version your application connects to and the Go version your application runs on. For more information, see the Compatibility page.
Address any breaking changes between the driver versions your application uses and your planned upgrade version in the Breaking Changes section.
Tip
To minimize the number of changes your application requires when upgrading driver versions in the future, use the Stable API.
Breaking Changes
A breaking change is a change of a convention or a behavior starting in a specific version of the driver. This type of change may prevent your application from working properly if not addressed before upgrading the driver.
The breaking changes in this section are categorized by the driver version that introduced them. When upgrading driver versions, address all the breaking changes between the current and upgrade versions.
Version 2.2 Breaking Changes
Drops support for MongoDB Server v3.6. The minimum supported MongoDB Server version is now v4.0. This also drops support for the
MONGODB-CR
authentication mechanism. To learn more about compatibility with MongoDB Server versions, see the Compatibility reference.
Version 2.0 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 toCursor.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 Limit Server Execution Time guide.
Removal of the
bson/primitive
package. This package is now merged with thebson
package. To update your code, remove anybson/primitive
import statements and change any instance ofprimitive.ObjectID
tobson.ObjectId
.