如何注册和使用mongoose深入

好的。 所以我试图做一些我的mongoose模型的嵌套人口。 而且我发现Mongoose-Deep-Populate是嵌套解决scheme的最简单的修复之一,但是,看起来很简单,我不知道如何正确注册插件。

我正在使用angular-fullstack项目,只是添加了deep-populate插件的npm install 。 然后我进入我的模型,并添加了这个:

 'use strict'; var deepPopulate = require('mongoose-deep-populate'); var mongoose = require('mongoose'), Schema = mongoose.Schema; var EntrySchema = new Schema({ articleId: Number, title: String, content: String, date: Date, children: [{ type: Schema.ObjectId, ref: 'Entry' }], forum: { type: Schema.ObjectId, ref: 'Forum' }, language: { type: Schema.ObjectId, ref: 'Language' }, orphan: Boolean, writer: { type: Schema.ObjectId, ref: 'User' }, type: String }).plugin(deepPopulate, options); module.exports = mongoose.model('Entry', EntrySchema); 

正如你所看到的,在我的模型中可能有多层次的嵌套entries 。 所以find他们,我写这个:

 // Get list of chapter entries exports.chapter = function(req, res) { Entry.find() .where('orphan').equals(true) .populate('children') .exec(function (err, entrys) { Entry.deepPopulate(docs, 'children', err, entrys) { if(err) { return handleError(res, err); } return res.json(200, entrys); }; }); }; 

但是这不起作用。 我很确定我做错了什么。 我已经检查了networking,但似乎没有find一个可以澄清我的错误的例子。 我现在已经来到你们我的大师们那里解决我的烦恼了。