var pageSchema = new Schema({
path: String,
body: String,
children: [pageSchema],
permanent: Boolean,
editable: Boolean
})
pageSchema.virtual('title').get(function(){
var index = this.path.lastIndexOf('/');
var title = this.path.substr(index + 1);
return title;
});
If I iterate over the 'children' field of a 'page', I can't get their 'title' through the virtual property method. It returns undefined.
There is a similar question where more than one schema was involved. The answer was to define the virtual properties before declaring the schema as embedded, but that cannot be the case here.