2016-11-07 10 views
2

謝罪これは既に尋ねられている場合、私の検索は同じ状況を起こさなかった。私は実験を要求したとき、私はelementsresourcesの配列とし、要素フィールドcomponentごとにオブジェクトを取得するように深い人口を実行したいサブグループのサブトピックの配列

var experimentSchema = new mongoose.Schema({ 

    name : 'string' 
    elements : [{ 
     type : mongoose.Schema.ObjectId, 
     ref: 'Element' 
    }], 
    resources : [{ 
     type : mongoose.Schema.ObjectId, 
     ref : 'Resource' 
    }], 

}) 


var elementSchema = new mongoose.Schema({ 
    name : 'string', 
    component : { 
     type : mongoose.Schema.ObjectId, 
     ref : 'Component' 
    } 
}) 

:私は何か以下のような2つのスキーマを持っていますも投入されました。成功なし

Experiment.findOne(query).populate(['resources','elements','elements.component']).exec(...) 

私はの線に沿っていくつかのことを試してみました。誰もこのタイプの操作に正しい構文を提供できますか?

ありがとうございます!

答えて

1

これが役に立ちます。

models.User.findOne(query) 
     .populate([{ 
     path: 'elements', 
     populate: { 
      path: 'components', 
      model: 'Component' 
      } 
     },{ 
     path:'resources' 
     }]) 
     .exec(...) 
関連する問題