brickyang / egg-mongo-native

MongoDB egg.js plugin using native driver.
MIT License
75 stars 11 forks source link

是不是在 egg 2.15 中使用需要用其他配置选项 #41

Closed luneice closed 4 years ago

luneice commented 4 years ago

依赖环境如下

package.json

"dependencies": {
    "egg": "^2.15.1",
    "egg-mongo-native": "^3.5.0",
    "egg-scripts": "^2.11.0"
  }

配置选项如下

plugin.js

exports.mongo = {
  enable: true,
  package: 'egg-mongo-native',
};

config.default.js
exports.mongo = {
    client: {
      host: 'localhost',
      port: '27017',
      name: 'example',
    },
  };

无法创建 mongo 数据库连接对象,然后导致 find 方法不是函数。调试时,mongo 数据类型为 object 不是 MongoDB 类型。

请问,问题出在哪里了?

luneice commented 4 years ago

问题找到了,依赖中缺少 "mongodb": "^3.1.10" 导致 mongo 对象无法生成。

brickyang commented 4 years ago

mongodb 是 egg-mongo-native 的依赖,不应该需要手动添加。