Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose virtual populate not working

// virtual pupulate
AuthorSchema.virtual('posts', {
  ref: 'BlogPost',
  localField: '_id',
  foreignField: 'author'
})

// add this in your schema if vritual is not work, this method working for me
AuthorSchema.set('toObject', { virtuals: true })
AuthorSchema.set('toJSON', { virtuals: true })
 
PREVIOUS NEXT
Tagged: #mongoose #virtual #populate #working
ADD COMMENT
Topic
Name
8+5 =