Virtual properties of embedded documents with same schema as parent document

17 views
Skip to first unread message

Gabriel Fernández Valdés

unread,
Feb 24, 2014, 5:54:24 AM2/24/14
to mongoo...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages