Argument of type ‘{ useNewUrlParser: boolean; useUnifiedTopology: boolean}’ is not assignable to parameter of type’

Hello I am using "mongodb": "^4.7.0"

This is the line of code that has an error:
const CLIENT: MongoClient = new MongoClient(MONGO_URI, OPTIONS);

This is the OPTIONS constant:

const OPTIONS = {

  useNewUrlParser: true,

  useUnifiedTopology: true,

};

This is the error:


Type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' has no properties in common with type 'MongoClientOptions'.

I’ve looked at these answers:

Note: I am not using mongoose like the others in the answers nor am I using poolSize.

Thank you for your time!

Hi @D_Guillaumant, welcome to the community.
As per the Connection Pool Options documentation:

In driver 3.5, we introduced some new connection pool-related options – maxPoolSize and minPoolSize – which were only respected when useUnifiedTopology was set to true . These options had legacy equivalents named poolSize and minSize , respectively, which could be used both with and without useUnifiedTopology set to true .

In driver 4.0, the legacy options have been removed, and only maxPoolSize and minPoolSize are supported. We have added options validation which should help you identify any usages of the old names.

Therefore you don’t need to pass these options:

And you can continue by connecting using the following syntax:

MongoClient.connect(process.env.MONGODB_URI)

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.