Mongoose warns that the Server Discovery and Monitoring engine is deprecated
current 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.
Fix it fast
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 mongoose2Match what you see, then jump to its fix
- 1
npm ls mongoose shows 5.x and the warning prints on every connectMongoose 5 is using the legacy topology engineFix - 2
The 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
You are still on Mongoose 5 and have no reason to stayAn old Mongoose major can simply be upgradedFix
- 1
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" src2Fix
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.jsConfirmed by mongoosejs.com
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" src2Fix
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 startConfirmed by mongoosejs.com
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 mongodb2Fix
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 testConfirmed by mongoosejs.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix