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

标签 node.js mongodb mongoose

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

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/

相关文章:

javascript - 在 discord.js 中使用音乐可能无法正常工作

node.js - Node js swig对象显示

java - 使用 MongoDB 和 Morphia 编译 GWT 应用程序

arrays - 无法将 EJS 变量插入 html scripttag 中的数组?

javascript - 使用 Express Node.js 和 mongoose 声明 session

node.js - 连接到 MongoLab 数据库时验证失败,代码 18

javascript - 如何根据 MongoDB 的内部数组检索前三个文档

mongodb - N :M relationships? 的 MongoDB 中级联删除的推荐等效项是什么

node.js - 插入 Mongoose 后找不到文档

node.js - 如何在 node.js 中处理标准输出