0
我想.populate
具体型号,但似乎忽略了第二select
命令,如果它是一个虚拟...猫鼬填充一个虚拟的而不是整个架构
// This won't work - it just returns the _id meaning it didn't populate
.populate({ path: 'user', select: 'post' }) // Post is a : virtual('post')
.populate('user', 'post') // Also doesn't work
// If I manually select all the fields the virtual does, that works of course
.populate({ path: 'user', select: '_id name image type' })
这里的虚拟我在用户对象上创建
// Here's the relating parts of the Model
var UserSchema = new Schema({
name : String,
type: {},
image : String
});
// Here's the virtual
UserSchema
.virtual('post')
.get(function() {
return {
'_id' : this._id,
'name' : this.name,
'type' : this.type,
'image' : this.image
};
});
我必须缺少一些东西...阅读文档,一切都很好。
谢谢!是的,这是我意识到我可能不得不做的......我也会看看populate-virtuals插件。感谢你的帮助 –