With mongoose, I want to populate a property inside a subdocument Array of my main document. Here is example:
var Question = new Schema({
title: {type: String},
answers: Schema.Types.Mixed, //{A:'',B:''}
category: {type: String},
type: {type: String},
enable: {type: Boolean, default: true},
sex: Number,
//random: {type: Number, default: Math.random},
createdAt: {type: Date, default: Date.now}
});
var User = new Schema({
username: {type: String},
password: {type: String},
typeQuestion: [{q: {type: Schema.Types.ObjectId, ref: 'Question'}, a: String,option:String }],
});
How to populate typeQuestion from User, Anyone can tell me how to do it?