Mongoose: nested ref models population

前端 未结 2 823
故里飘歌
故里飘歌 2021-01-16 18:16

How can I populate nested referenced models?

For example:

// \'Collection\' model
var CollectionSchema = new Schema({
  collection_name: String,
  _g         


        
相关标签:
2条回答
  • 2021-01-16 18:32

    I would rather do

    var Group = mongoose.model('Group', GroupSchema);
    
    Group.find().populate('_item _meta').exec(function (error, groups) {
      // ...
    });
    
    0 讨论(0)
  • 2021-01-16 18:35
    var Group = mongoose.model('Group', GroupSchema);
    Group.find().populate('_item').populate('_meta').exec(function (error, groups) {
      //groups will be an array of group instances and
      // _item and _meta will be populated
    });
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题