mongoose virtual populate not working

JavaScript
// 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 })
Source

Also in JavaScript: