MongoDB driver vs server version mismatch (compatibility) in CI
The Node driver and the mongod server versions are outside each other supported range. CI pins one but not the other, so a command the driver expects is unsupported, or the server rejects the driver handshake.
What this error means
Connection or commands fail with messages like "Server at ... reports maximum wire version N, but this version of the driver requires at least M" or an unsupported-command error after an image bump.
MongoCompatibilityError: Server at localhost:27017 reports maximum wire version 6,
but this version of the Node.js Driver requires at least 7 (MongoDB 4.0)Common causes
The service image and driver drifted apart
The mongo: service image was bumped (or is very old) while the driver in package.json stayed pinned, crossing the supported wire-version range.
A too-new server feature used by an old driver
A newer server default or feature is not understood by an older driver, so a command is reported unsupported.
How to fix it
Pin compatible driver and server versions
- Check the driver compatibility matrix for the server version.
- Pin the
mongo:service image and the driver to a supported pair. - Bump both together, not one at a time.
services:
mongo:
image: mongo:7 # keep in sync with the pinned driverUpgrade the lagging side
Update whichever is out of range (usually the driver) so the wire versions overlap.
npm install mongodb@6How to prevent it
- Pin both the service image and the driver, and bump them together.
- Consult the compatibility matrix before upgrading either side.
- Test against the same server major version you run in production.