Search
 
SCRIPT & CODE EXAMPLE
 

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 })
Comment

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');
Comment

PREVIOUS NEXT
Code Example
Javascript :: hasownproperty.call 
Javascript :: gsap react 
Javascript :: javascript easy resize for screen size 
Javascript :: npm font awesome angular 12 
Javascript :: function shorthand javascript 
Javascript :: express example 
Javascript :: var hoisting.js 
Javascript :: convert string to array with condition javascirpt 
Javascript :: replace spaces with dashes 
Javascript :: how to add a property to a class in javascript 
Javascript :: hoisting in javascript mdn 
Javascript :: const in javascript 
Javascript :: how to remove elements from array 
Javascript :: js set to array 
Javascript :: nodejs: express: package for Router 
Javascript :: cookie-parser get cookie 
Javascript :: Set Default Parameter Value 
Javascript :: Angular passing function as component input 
Javascript :: unexpected end of json input 
Javascript :: es6 class example 
Javascript :: javascript function arguments 
Javascript :: javascript static class variable 
Javascript :: conver all array to object 
Javascript :: javaScript throw statement 
Javascript :: javascript get all options from select 
Javascript :: regex serch in capture group 
Javascript :: how to console log in react native 
Javascript :: drag n drop file upload react 
Javascript :: indexof 
Javascript :: JavaScript slice() Syntax 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =