I have a couple Schemas:
var parentSchema = new Schema({name: String});
var childSchema = new Schema({
name: String,
parent: {type: Schema.ObjectId, ref: 'Parent'}
});
I want to be able to call Child.find().populate('parent')
and then use the following virtual getter:
childSchema.virtual('url').get(function () {
return "/" + this.parent.name + "/" + this.name
});
However, when I call the find().populate()
and then pass the resulting child to my view, and attempt to use child.url
, I always get parent.name
set to undefined. What am I doing wrong?