I have the following setup. Typescript and Node, and combination of Mongoose and Typegoose for models. This is how I obtain my database
import mongoose from "mongoose";
import { Db } from "mongodb";
import config from "@/config";
export default async (): Promise<Db> => {
const connection = await mongoose.connect(config.databaseUrl, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
return connection.connection.db;
};
And this is the error that I get
Type 'Db' is missing the following properties from type 'Db': readConcern, readPreference, bsonOptions, namespace, and 4 more.
Somewhere along the line of updating dependencies, this part got messed up, it's weird because connection.db is of type Mongodb.Db...
These are my versions
"dependencies": {
"@typegoose/typegoose": "8.3.0",
"@types/mongodb": "3.6.5",
"mongodb": "4.1.2",
"mongoose": "5.13.8",
},
"devDependencies": {
"tsconfig-paths": "^3.11.0",
"typescript": "4.1.3"
}
Typegoose required me to use 5.13.8 version (while i previously used 5.12 something) and this seems to broke everything.
CodePudding user response:
this issue was also brought up on the discord and discussed there, the answer was:
In the project [email protected]
was installed, where as [email protected]
only supports (and uses) [email protected]
(and @ŧypes/[email protected]
) and so the types were incompatible.