mongodb
protocol_error
ai_generated
true
MongoServerError: 事务 API 版本错误:预期 API 版本 '1' 但收到 '2'
MongoServerError: Transaction API version error: expected API version '1' but received '2'
ID: mongodb/transaction-api-version-error
90%修复率
87%置信度
1证据数
2024-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
根因分析
驱动程序或应用程序尝试使用不受支持的事务 API 版本,通常是由于驱动程序/库版本与 MongoDB 服务器不匹配。
English
A driver or application attempted to use an unsupported transaction API version, typically due to driver/library version mismatch with the MongoDB server.
官方文档
https://www.mongodb.com/docs/manual/reference/command/commitTransaction/解决方案
-
升级 MongoDB 驱动程序到与服务器 API 版本兼容的版本。对于 Node.js:npm install [email protected]。对于 Python:pip install pymongo==4.6.0。
-
在连接字符串中显式设置 API 版本:mongodb://localhost:27017/?apiVersion=1 以强制兼容性。
无效尝试
常见但无效的做法:
-
80% 失败
Upgrading the MongoDB server to the latest version doesn't fix the mismatch if the driver is outdated.
-
90% 失败
Setting transaction options to empty object in the driver is ignored because the API version is negotiated at connection time.