mongodb
protocol_error
ai_generated
true
MongoServerError: Transaction API version error: expected API version '1' but received '2'
ID: mongodb/transaction-api-version-error
90%Fix Rate
87%Confidence
1Evidence
2024-06-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
Root Cause
A driver or application attempted to use an unsupported transaction API version, typically due to driver/library version mismatch with the MongoDB server.
generic中文
驱动程序或应用程序尝试使用不受支持的事务 API 版本,通常是由于驱动程序/库版本与 MongoDB 服务器不匹配。
Official Documentation
https://www.mongodb.com/docs/manual/reference/command/commitTransaction/Workarounds
-
95% success Upgrade the MongoDB driver to a version compatible with the server API version. For Node.js: npm install [email protected]. For Python: pip install pymongo==4.6.0.
Upgrade the MongoDB driver to a version compatible with the server API version. For Node.js: npm install [email protected]. For Python: pip install pymongo==4.6.0.
-
85% success Set the API version explicitly in the connection string: mongodb://localhost:27017/?apiVersion=1 to force compatibility.
Set the API version explicitly in the connection string: mongodb://localhost:27017/?apiVersion=1 to force compatibility.
中文步骤
升级 MongoDB 驱动程序到与服务器 API 版本兼容的版本。对于 Node.js:npm install [email protected]。对于 Python:pip install pymongo==4.6.0。
在连接字符串中显式设置 API 版本:mongodb://localhost:27017/?apiVersion=1 以强制兼容性。
Dead Ends
Common approaches that don't work:
-
80% fail
Upgrading the MongoDB server to the latest version doesn't fix the mismatch if the driver is outdated.
-
90% fail
Setting transaction options to empty object in the driver is ignored because the API version is negotiated at connection time.