Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Mongoose warns that the Server Discovery and Monitoring engine is deprecated

Errorcurrent Server Discovery and Monitoring engine is deprecated, and will be removed in a future version.

Short answer

The warning comes from Mongoose 5, which still connects with the legacy topology engine. Either set useUnifiedTopology and drop the reconnect options it replaces, or upgrade to Mongoose 6 or newer, where the option is gone and the new engine is always on.

  • Applies to Mongoose 5.13, Mongoose 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which Mongoose version is installed. The right fix depends on whether it is 5.x or 6 and above.

    npm ls mongoose
  2. 2Match what you see, then jump to its fix

    1. 1npm ls mongoose shows 5.x and the warning prints on every connectMongoose 5 is using the legacy topology engineFix
    2. 2The warning is gone but connections misbehave, or the config still lists autoReconnect, reconnectTries or reconnectIntervalOptions of the old engine are still in the connect callFix
    3. 3You are still on Mongoose 5 and have no reason to stayAn old Mongoose major can simply be upgradedFix

What does the error look like?

  • current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version.

Cause 1 of 3

Mongoose 5 is using the legacy topology engine

1Check

Look at how the connection is opened. If useUnifiedTopology is not set, the old engine is used and the warning is printed.

grep -rn "mongoose.connect\|useUnifiedTopology" src

2Fix

Turn the new engine on for the connection.

mongoose.set('useUnifiedTopology', true);
await mongoose.connect(process.env.MONGODB_URI);

3Verify

Start the app and confirm the warning is gone.

node dist/server.js

Confirmed by mongoosejs.com

Did this fix it?

Cause 2 of 3

Options of the old engine are still in the connect call

1Check

The new engine does not support those three options, so they must not stay in connect() or createConnection().

grep -rn "autoReconnect\|reconnectTries\|reconnectInterval" src

2Fix

Delete them from the options object.

await mongoose.connect(process.env.MONGODB_URI, {
  // autoReconnect, reconnectTries, reconnectInterval removed
});

3Verify

Restart the app and confirm it connects.

npm start

Confirmed by mongoosejs.com

Did this fix it?

Cause 3 of 3

An old Mongoose major can simply be upgraded

1Check

Mongoose 6 treats useNewUrlParser, useUnifiedTopology and useCreateIndex as always on and no longer accepts those options (useFindAndModify is always off).

npm ls mongoose mongodb

2Fix

Upgrade Mongoose and delete the use* options from your connect call.

npm install mongoose@latest
// before: await mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
await mongoose.connect(uri);

3Verify

Run your tests, then start the app.

npm test

Confirmed by mongoosejs.com

Did this fix it?

How do I stop it coming back?

  • Read the Mongoose migration guide before each major upgrade.
  • Keep connect options in one module so one edit changes every connection.
  • Fail the build on warnings that mention deprecation, so they are fixed while small.

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 built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

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