所以我试图填充已经填充的文档:
postModel
.findOne({
_id: postId
}).select()
.populate('author')
.populate('sharedBy')
.populate('replies')
.exec(function(err, post) {
if (err) return err;
但是,该replies
数组将包含一堆帖子,其中包含我还需要填充的键author
。sharedBy
这是我的策略:
.populate('author')
.populate('sharedBy')
.populate('replies')
.exec(function(err, post) {
if (err) return err;
post.deepPopulate(function(err, post){
并且deepPopulate
:
PostSchema.method('deepPopulate', function(cb) {
var post = this;
async.map(this.replies, function(reply, done) {
mongoose.model('Post', PostSchema).findOne({
_id: reply._id
}).select().populate('author').populate('sharedBy').exec(done);
}, function(err, replies) {
post.replies = replies;
cb(err, post);
});
});
它找到了replies
罚款,但我似乎无法将它们放回传递的原始帖子中!有任何想法吗?