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 :: how to get the end of an array javascript 
Javascript :: jquery trigger 
Javascript :: make string json object vue 
Javascript :: select all checkboxes jquery 
Javascript :: github authorization javascript 
Javascript :: p5.js style 
Javascript :: discord.js role regex 
Javascript :: ascii to hex js 
Javascript :: regex pater for only 4 or 6 digits 
Javascript :: get the middle character js 
Javascript :: isobject javascript 
Javascript :: js set get first value 
Javascript :: remove duplicates from array js lodash 
Javascript :: error placement jquery validation 
Javascript :: how to flatten array with reduce in javascript 
Javascript :: node js utf8 encode 
Javascript :: react absolute import 
Javascript :: express serve static files 
Javascript :: turn nodelist into array 
Javascript :: how to fix eslint error no-prototype-builtins 
Javascript :: javascript wait 10 seconds 
Javascript :: javascript add quote comma 
Javascript :: new fabric canvas set width 
Javascript :: javascript change color of button 
Javascript :: regex all starting with 
Javascript :: react fontawesome 
Javascript :: pdf dark 
Javascript :: Finding the array element: 
Javascript :: shadowoffset react native constructor 
Javascript :: windows.load with settimeout 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =