Error
Error Code:
322
MongoDB Error 322: API Version Mismatch
Description
MongoDB Error 322, 'A P I Version Error', indicates an incompatibility between the MongoDB driver or client application and the MongoDB server's expected API version. This typically occurs when a client attempts to connect to a server using an API version that the server does not support, or vice-versa, often after upgrades or when using mixed versions.
Error Message
A P I Version Error
Known Causes
3 known causesOutdated Client or Driver
The MongoDB client application or driver used to connect is older than the server and does not support the server's required API version.
Newer Client, Older Server
A newer MongoDB client or driver is attempting to connect to an older MongoDB server that does not support the API version requested by the client.
Incorrect API Version Configuration
The `apiVersion` option specified in the connection string or client configuration does not align with the MongoDB server's supported API versions.
Solutions
3 solutions available1. Align MongoDB Driver and Server Versions easy
Ensure your MongoDB driver version is compatible with your MongoDB server version.
1
Identify your MongoDB server version. You can do this by running `mongod --version` in your terminal or connecting to your MongoDB instance using the `mongo` shell and running `db.version()`.
mongod --version
# or
db.version()
2
Consult the MongoDB documentation for your specific server version to determine the recommended or compatible driver versions. Search for 'MongoDB <server_version> driver compatibility'.
text
3
Update your application's MongoDB driver to the compatible version. This will typically involve modifying your project's dependency management file (e.g., `package.json` for Node.js, `pom.xml` for Java, `requirements.txt` for Python).
Example for Node.js (package.json):
"dependencies": {
"mongodb": "^4.1.0"
}
Run:
npm install
# or
yarn install
4
Rebuild and restart your application to use the updated driver.
text
2. Check API Version in Connection String medium
Verify if a specific API version is being enforced in your connection string and align it with the server's capabilities.
1
Locate the connection string used by your application to connect to MongoDB.
text
2
Examine the connection string for any parameters related to API versioning. For example, some drivers might have options like `apiVersion`. If you find such a parameter, check its value.
Example connection string snippet:
mongodb://localhost:27017/?replicaSet=rs0&authSource=admin&apiVersion=1
3
If an `apiVersion` is specified, ensure it's a value supported by your MongoDB server version. Consult the MongoDB documentation for the supported API versions for your specific server release.
text
4
If the `apiVersion` is explicitly set to a version not supported by your server, either remove the parameter to let the driver use the default or set it to a compatible version.
Example (removing apiVersion):
mongodb://localhost:27017/?replicaSet=rs0&authSource=admin
5
Restart your application after modifying the connection string.
text
3. Upgrade MongoDB Server and Drivers advanced
Address potential mismatches by upgrading both your MongoDB server and application drivers to recent, compatible versions.
1
Plan for a MongoDB server upgrade. This is a significant undertaking and requires careful consideration of downtime, backups, and compatibility with other components of your infrastructure.
text
2
Perform a full backup of your MongoDB data before proceeding with any upgrade.
text
3
Follow the official MongoDB documentation for upgrading your specific MongoDB server version. This usually involves stopping the current server, installing the new version, and starting it.
text
4
After successfully upgrading the MongoDB server, identify the latest stable MongoDB driver versions compatible with your new server version.
text
5
Update all applications that connect to this MongoDB instance to use the latest compatible driver versions. This follows the steps outlined in 'Align MongoDB Driver and Server Versions'.
text
6
Thoroughly test all applications after the upgrade to ensure full functionality and absence of API versioning issues.
text