Maaz Zindani

Loading the index…

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

Node.js warns that useNewUrlParser or useUnifiedTopology has no effect

ErroruseNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version

Short answer

Since Node.js Driver 4.0.0 the driver always uses the new URL parser and unified topology, so passing useNewUrlParser or useUnifiedTopology does nothing and prints a warning. Delete both options from MongoClient or mongoose.connect. Driver 7.0 removed them from the options type, so leftover code can also fail type checks.

  • Applies to mongodb driver 6.x, mongodb driver 7.x, Mongoose 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place the two options are passed, including config files and copied tutorial snippets.

    grep -rn "useNewUrlParser\|useUnifiedTopology" --include=*.js --include=*.ts --include=*.mjs .
  2. 2Match what you see, then jump to its fix

    1. 1The warning prints once at start-up and your code calls new MongoClient(uri, { useNewUrlParser: true, ... }).The options are passed to new MongoClientFix
    2. 2The warning appears when you call mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }).The options are passed to mongoose.connectFix
    3. 3TypeScript no longer lists useNewUrlParser and useUnifiedTopology in MongoClientOptions after the upgrade.You upgraded to Node.js driver 7 and the options are gone from the typesFix

What does the error look like?

  • useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
  • useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version

Cause 1 of 3

The options are passed to new MongoClient

1Check

The driver's own option table marks both options as having no effect since 4.0.0, and its source emits the warning when either is given.

grep -rn "new MongoClient" --include=*.js --include=*.ts .

2Fix

Remove both options. A plain client needs only the connection string.

const client = new MongoClient(uri);
await client.connect();

3Verify

Start the app again; the warning no longer prints.

node app.js

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

The options are passed to mongoose.connect

1Check

Mongoose passes its options to the driver. The Mongoose 6 guide calls these options no longer supported, says they are treated as enabled, and asks you to remove them.

npm ls mongoose mongodb

2Fix

Remove the options from mongoose.connect.

await mongoose.connect(uri);

3Verify

Restart the app and check the console.

node app.js

Confirmed by mongoosejs.com

Did this fix it?

Cause 3 of 3

You upgraded to Node.js driver 7 and the options are gone from the types

1Check

The driver's upgrade guide lists MongoClientOptions.useNewUrlParser and MongoClientOptions.useUnifiedTopology among the options removed in version 7.0.

npm ls mongodb

2Fix

Remove the options from your code; there is no replacement because the behaviour is always on.

const client = new MongoClient(uri, { maxPoolSize: 20 });

3Verify

Run your TypeScript build or tests again.

npm test

Confirmed by mongodb.com

Did this fix it?

How do I stop it coming back?

  • Copy connection code from the current driver docs, not from older tutorials.
  • Read the upgrade guide before moving to a new major version of the mongodb package.
  • Keep connection options in one module so cleanup happens in one place.

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.