对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

升级驱动程序版本

本页介绍了升级到新版本的Go驱动程序时必须对应用程序进行的更改。

升级前,请执行以下操作:

  • 确保新的Go驱动程序版本与应用程序连接的MongoDB Server版本以及应用程序运行的Go版本兼容。有关更多信息,请参阅兼容性页面。

  • 要解决应用程序使用的驱动程序版本与计划升级版本之间发生的任何破坏性变更,请参阅破坏性变更部分。

提示

为了最大限度地减少应用程序将来升级驱动程序版本时所需的更改数量,请使用 Stable API。

重大更改是对从特定版本的驱动程序开始的约定或行为的更改。 如果在升级驱动程序之前未解决,此类更改可能会导致应用程序无法正常工作。

本部分中的破坏性变更 (breaking change) 按引入它们的驱动程序版本进行分类。升级驱动程序版本时,请解决当前版本和升级版本之间的所有破坏性变更 (breaking change)。

  • Drops support for Go versions earlier than 1.25. The minimum supported Go version is now 1.25, and the Go driver supports the two most recent Go minor versions. To learn more about compatibility with Go versions, see the Compatibility page.

  • Drops support for MongoDB Server v4.2. The minimum supported MongoDB Server version is now 4.4. To learn more about compatibility with MongoDB Server versions, see the Compatibility page.

  • 删除对MongoDB Server v4.0 的支持。现在支持的最低MongoDB Server版本为 v4.2。要学习;了解有关MongoDB Server版本兼容性的更多信息,请参阅兼容性页面。
  • 删除对MongoDB Server v3.6 的支持。现在支持的最低MongoDB Server版本为 v4.0。这也删除了对 MONGODB-CR身份验证机制的支持。要学习;了解有关MongoDB Server版本兼容性的更多信息,请参阅兼容性页面。
  • mongo.Connect() 不接受 Context 参数。此方法只接受一个选项对象。要查看使用此方法的示例,请参阅连接指南中的连接示例代码

  • Cursor.SetMaxTime() 方法已重命名为 Cursor.SetMaxAwaitTime()。 此方法指定服务器等待使用可追加可追加游标从固定大小集合中检索新文档的最长时间。

  • 删除特定于操作的超时选项。以下字段和 setter 方法已从驱动程序中删除:

    • 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

    相反,您可以在客户端上或上下文中设立超时。了解详情,请参阅“限制服务器执行时间”指南。

  • 删除 bson/primitive包。此包现已与 bson包合并。要更新代码,删除所有 bson/primitive 导入语句,并将 primitive.ObjectID 的任何实例更改为 bson.ObjectId

要学习;了解如何将应用程序从 v1 升级到 v2 ,请参阅Go驱动程序.2 0迁移指南。

给本页内容打分

在此页面上