这是我用来连接到数据库的代码:
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/47300111/