Monday, 2 April 2018

Mongoose populate requirements

I was wondering if I am required to save referenced child item in array at parent item's schema. Because even if I don't I can still make a popullation.For example:Author: { fullname: { type: String }, books: [{ type: Schema.ObjectId, ref: 'Books' ]}, } Book: { title: { type: String }, author: { type: Schema.ObjectId, ref: 'Author'}, }Book.findById(id).populate('author'); // Works .Author: { fullname: { type: String }, } Book: { title: { type: String }, author: { type: Schema.ObjectId, ref: 'Author'}, }Book.findById(id).populate('author'); // Also works

Submitted April 02, 2018 at 01:41PM by dq_ss

No comments:

Post a Comment