Answers for "mongoose virtual populate just one"

0

mongoose virtual populate

// Specifying a virtual with a `ref` property is how you enable virtual
// population
AuthorSchema.virtual('posts', {
  ref: 'BlogPost',
  localField: '_id',
  foreignField: 'author'
});

const Author = mongoose.model('Author', AuthorSchema, 'Author');
const BlogPost = mongoose.model('BlogPost', BlogPostSchema, 'BlogPost');
Posted by: Guest on January-22-2022

Code answers related to "mongoose virtual populate just one"

Code answers related to "Javascript"

Browse Popular Code Answers by Language