I am trying to connect my Node.js server to Atlas mongo database. I am using mongoose for this.
await mongoose
.connect(process.env.MONGO_URI!, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
poolSize: parseInt(process.env.POOL_SIZE!),
})
.then((res) => {
console.log(
'Connected to Distribution API Database - Initial Connection'
);
})
.catch((err) => {
console.log(
`Initial Distribution API Database connection error occured -`,
err
);
});
My dependencies related to this in the package.json file is as below
"dependencies": {
"@types/mongoose": "5.7.29",
"mongoose": "5.9.21",
"typescript": "3.9.5"
},
This was working earlier without any issues (I did not update @types/mongoose or mongoose versions at all) and suddenly now I am getting the below error
Compilation error in /app/src/index.ts
Using ts-node version 8.10.2, typescript version 3.9.5
[ERROR] 16:25:18 ⨯ Unable to compile TypeScript: src/index.ts(59,11): error TS2769: No overload matches this call.
Overload 1 of 3, '(uris: string, callback: (err: MongoError) => void): Promise<typeof import("mongoose")>', gave the following error.
Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; useCreateIndex: boolean; useFindAndModify: boolean; poolSize: number; }' is not assignable to parameter of type '(err: MongoError) => void'.
Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type '(err: MongoError) => void'.
Overload 2 of 3, '(uris: string, options?: ConnectionOptions | undefined): Promise<typeof import("mongoose")>', gave the following error.
Argument of type '{ useNewUrlParser: true; useUnifiedTopology: true; useCreateIndex: true; useFindAndModify: false; poolSize: number; }' is not assignable to parameter of type 'ConnectionOptions'.
Object literal may only specify known properties, and 'poolSize' does not exist in type 'ConnectionOptions'
Can someone help me on this?? Really appreciate any thoughts on this.
Thanks