我有一个文章架构,用于用户在我的网站上发布的文章。它引用了用户集合:
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 调用上添加一个 post hook 来填充参考:
ArticleSchema.post('find', function (doc) {
doc.populate('author');
});
由于某种原因,挂钩中返回的文档没有填充方法。我是否必须使用 ArticleSchema 对象而不是在文档级别进行填充?