【发布时间】:2021-12-28 16:09:27
【问题描述】:
我的 GitHub 仓库:https://github.com/safiullah7/legan
分支:redux
我正在关注本教程:https://tomanagle.medium.com/build-a-rest-api-with-node-js-typescript-mongodb-b6c898d70d61 而且我无法连接到我的 mongodb。 这是我尝试与 mongodb 连接的代码文件:
import config from "config";
import log from "../logger";
function connect() {
const dbUri = config.get("dbUri") as string;
return mongoose
.connect(dbUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
log.info("Database connected");
})
.catch((error) => {
log.error("db error", error);
process.exit(1);
});
}
export default connect;
编译器给出以下错误:
No overload matches this call.
Overload 1 of 3, '(uri: string, callback: CallbackWithoutResult): void', gave the following error.
Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'CallbackWithoutResult'.
Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'CallbackWithoutResult'.
Overload 2 of 3, '(uri: string, options?: ConnectOptions | undefined): Promise<typeof import("mongoose")>', gave the following error.
Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'ConnectOptions'.
Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'ConnectOptions'.
我是 typescript 和 node/mongoos 的新手。非常感谢您的帮助。
【问题讨论】:
-
你可以从 Mongoose 文档中试试这个:mongoosejs.com/docs/typescript.html
-
参考支持的完整列表
options:MongoDB Node.js driver docs for connect()
标签: node.js typescript mongodb mongoose