这是我用来连接数据库的代码:
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”的任何信息。
你们知道怎么做吗?
原文由 Tiago Bértolo 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果没有 Typescript ,您几乎可以忽略该问题并使用
Mongoose.connect(databaseUri, { useMongoClient: true })
。如果您真的想避免出现警告,请避免使用 4.11.0 版本。
我更新到版本 4.11.1 并且由于 @types/mongoose@4.7.18 尚未更新并且他们没有在 — 中提及字段
useMongoClient
ConnectionOptions
,这就是我导入的方式模块:然后使用了这个功能: