0
私はmongooseバージョン4.4.10を使用しています。ここに私のスキーマの詳細があります。私は結果 の一環として、私は唯一のRespのコレクションの結果を得るSurveyResponseの収集結果をアクセスもすることはできませんよ、次のfindでpopulateを使用して、マングースの2つのコレクションをリンクするにはどうすればいいですか?
var RespSchema = new mongoose.Schema({
surveyResponseId : {type: mongoose.Schema.Types.ObjectId,
ref: 'SurveySResponsechema',
required: true,
index : true},
customerSurveyId : {type: mongoose.Schema.Types.ObjectId,
ref: 'CustomerSurveySchema',
required: true,
index : true},
version : Number,
question : Number,
responseType : String, // single or multiple-choice not implemented
response : [String],
responseNum : [Number],
created_dt : { type: Date, default: Date.now }
var SurveyResponseSchema = new mongoose.Schema({
customerSurveyId : {type: mongoose.Schema.Types.ObjectId,
ref: 'CustomerSurveySchema',
required: true,
index : true},
deviceId : String, // whch Android Tableet is runing this
version : Number,
taken : Boolean,
created_dt : { type: Date, default: Date.now }
});
mongoose.model('SurveyResponse', SurveyResponseSchema);
mongoose.model('Resp', RespSchema);
var Resp = mongoose.model('Resp');
var SurveyResponse = mongoose.model('SurveyResponse');
Resp.find({created_dt: {"$gt": new Date("2016-03-31T09:20:00Z")}})
.sort('customerSurveyId')
.populate('SurveyResponse')
.exec(function(err, results) {
if (err) return err;
console.log('results is:', JSON.stringify(results));
});
。
コレクションに結合するコレクションまたはキーの名前を入力する必要がありますか?これはどちらもうまくいかなかった。私はモデルがスキーマとは異なるものは含めなかった。 mongoose.model( 'SurveyResponse'、SurveyResponseSchema); –