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

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

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 })

https://stackoverflow.com/questions/44749700/

相关文章:

node.js - Meteor - collection.find() 总是返回所有字段

c# - 将字符串转换为 MongoDB BsonDocument

node.js - Express.js 在 MEAN 堆栈中做了什么?

mongodb - 从 Mongoose 模型中获取模式属性

mongodb - 将对象插入 Mongoose 中的数组模式

javascript - 如何获取在另一个模型中定义的 Mongoose 数据库的架构

mongodb - Mongo,通过 id 列表查找

php - MongoDB 和 CodeIgniter

date - 在MongoDB中按日期分组

mongodb - 如何在 docker 容器中启动 mongodb shell?