Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

The MongoDB Node.js driver refuses an old server because of its wire version

Your error

Server at localhost:27017 reports wire version 8, but this version of the driver requires at least 9 (MongoDB 4.4).2 more lines it can show

Fix it fast

Most common cause, 1 of 2

Driver 7.6+ or Mongoose 9.10+ meets a MongoDB 4.2 server

The lasting fix is a server on 4.4 or newer.

Fix
# stay on 4.2 for now: last releases before the cut
npm install mongodb@7.5.0      # apps that use the driver directly
npm install mongoose@9.9.5     # apps that use Mongoose (depends on mongodb ~7.5)
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

The message Server at host reports wire version 8, but this version of the driver requires at least 9 (MongoDB 4.4) means the server is older than the driver allows. mongodb 7.6.0 and Mongoose 9.10.0 dropped MongoDB 4.2; mongodb 6.17.0 and Mongoose 8.16.0 dropped 4.0. Upgrade the server one major at a time, or pin the older client meanwhile.

  • Applies to mongodb (Node.js driver) 7.9.1, Mongoose 9.12.2, Mongoose 8.24.x, Node.js 20.19 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List every copy of the driver in the project and which package pulled it in, then read the number in brackets at the end of the error. MongoDB 4.4 in brackets is cause 1; MongoDB 4.2 is cause 2.

Run this first
npm ls mongodb mongoose

Then find the line you see in this list and open its fix:

  1. 1Driver 7.6+ or Mongoose 9.10+ meets a MongoDB 4.2 serverThe error ends with requires at least 9 (MongoDB 4.4), and npm ls shows mongodb 7.6.0 or newer
  2. 2Driver 6.17+ or Mongoose 8.16+ meets a MongoDB 4.0 serverThe error ends with requires at least 8 (MongoDB 4.2), and npm ls shows a mongodb 6.x release from 6.17.0 on

What does the error look like?

  • Server at localhost:27017 reports wire version 8, but this version of the driver requires at least 9 (MongoDB 4.4).
  • Server at localhost:27017 reports wire version 7, but this version of the driver requires at least 8 (MongoDB 4.2).
  • MongoCompatibilityError

Cause 1 of 2

Driver 7.6+ or Mongoose 9.10+ meets a MongoDB 4.2 server

You seeThe error ends with requires at least 9 (MongoDB 4.4), and npm ls shows mongodb 7.6.0 or newer

Check

The driver needs at least MongoDB 4.4 since release 7.6.0, which throws an error when it connects to a 4.2 or older server. Mongoose 9.10.0 moved to that driver, so a routine Mongoose update inside the 9.x range can break an app that has always run on 4.2.

Check
npm ls mongodb
grep -n '"mongoose"\|"mongodb"' package.json

Fix

The lasting fix is a server on 4.4 or newer. MongoDB's upgrade guides require going through each major series in turn (4.2, 4.4, 5.0 and onward), each with its own featureCompatibilityVersion step. Until that is done, pin the last client release that still accepts 4.2.

Fix
# stay on 4.2 for now: last releases before the cut
npm install mongodb@7.5.0      # apps that use the driver directly
npm install mongoose@9.9.5     # apps that use Mongoose (depends on mongodb ~7.5)

Verify

npm ls shows mongodb 7.5.x and the app connects without the compatibility error. After the server upgrade, remove the pin.

Verify
npm ls mongodb && node app.js

Confirmed by github.com

Did this fix it?

Cause 2 of 2

Driver 6.17+ or Mongoose 8.16+ meets a MongoDB 4.0 server

You seeThe error ends with requires at least 8 (MongoDB 4.2), and npm ls shows a mongodb 6.x release from 6.17.0 on

Check

Release 6.17.0 of the Node.js driver removed MongoDB 4.0, so any 6.17 or later build refuses a 4.0 or older server. Mongoose 8.16.0 switched to that driver line, and every later 8.x release keeps the newer driver, so moving to Mongoose 9 does not help either.

Check
npm ls mongodb

Fix

Upgrade the server through 4.2 and 4.4 at minimum, in order. As a stopgap, hold the client at the last 4.0-capable release: mongodb 6.16.0, or Mongoose 8.15.2, which depends on mongodb ~6.16.0.

Fix
npm install mongodb@6.16.0
# or, for Mongoose projects
npm install mongoose@8.15.2

Verify

The app connects, and npm ls lists only mongodb 6.16.x. Plan the server upgrade before removing the pin.

Verify
npm ls mongodb

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Write the minimum MongoDB server version next to the Mongoose or driver version in the README, and check it when Renovate or Dependabot opens an update.
  • Use an exact version or a lockfile for mongoose and mongodb so a fresh install on CI cannot jump past your server's floor.
  • Run the test suite in CI against the same MongoDB major version as production, using that version's Docker image.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Workforce.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.