mongoose怎么populate一个对象数组里的某个属性字段?

新手上路,请多包涵

使用Mongoose时, 我想在User里populate一个对象数组字段里的一个属性q

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 }],    
});

有人知道怎么实现吗

阅读 6.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题