猫鼬深人口,不工作

时间:2018-01-26 17:04:14

标签: javascript node.js mongodb mongoose

我正在构建一个需要使用mongoose-deep-populate的网络应用,我使用npm安装了它。但我仍然得到以下错误:

Error: Plugin was not installed
at Query.deepPopulate (/Users/nikhilb/nodeapp/tracking_app/node_modules/mongoose-deep-populate/lib/plugin.js:30:15)
at /Users/nikhilb/nodeapp/tracking_app/routes/training.js:38:8
at process._tickCallback (internal/process/next_tick.js:109:7)

它说的插件没有安装,但在我的package.json文件中安装了它:

"mongoose": "^5.0.0",
"mongoose-deep-populate": "^3.0.0"

请提前帮助我。

编辑:

我要求它:

var deepPopulate = require('mongoose-deep-populate')(mongoose);

1 个答案:

答案 0 :(得分:1)

您需要在架构中注册插件。例如:

var deepPopulate = require('mongoose-deep-populate')(mongoose)

MySchema.plugin(deepPopulate)

如果需要,您可以将选项作为第二个参数传递。