我在我的网站上有一份由用户发布的文章模式。 它引用了“用户”集合:
var ArticleSchema = new Schema({
title: { // NO MARKDOWN FOR THIS, just straight up text for separating from content
type: String,
required: true
},
author: {
type: Schema.Types.ObjectId,
ref: 'User'
}
});
我希望在所有的find/findOne调用中都能使用后置钩子来填充引用:
ArticleSchema.post('find', function (doc) {
doc.populate('author');
});
由于某些原因,在钩子中返回的文档没有populate方法。我是否需要使用ArticleSchema对象而不是在文档级别上进行填充?