gpt4 book ai didi

node.js - 如何设置 useMongoClient (Mongoose 4.11.0)?

转载 作者:IT老高 更新时间:2023-10-28 11:16:38 26 4
gpt4 key购买 nike

这是我用来连接数据库的代码:

private connectDatabase(databaseUri: string): Promise<Mongoose.Connection> {
return Mongoose.connect(databaseUri).then(() => {
debug('Connected to MongoDB at %O', databaseUri);
return Mongoose.connection;
});
}

今天我将 Mongoose 更新到 4.11.0 版,运行测试时收到此警告:

(node:4138) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0,
use `openUri()` instead, or set the `useMongoClient` option if using `connect()`
or `createConnection()`

我找不到任何关于如何“设置 useMongoClient”的信息。

你们知道怎么做吗?

最佳答案

这就是你使用 useMongoClient 的方式:

mongoose.connect('mongodb://localhost/advisorDemoTestDB', { useMongoClient: true })

关于node.js - 如何设置 useMongoClient (Mongoose 4.11.0)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44749700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com