이이 문제를 해결하는 데 도움이 필요합니다. 채우기 메서드를 사용하여 ID를 reerenced 문서로 바꾸려고합니다. 그러나 반환 된 결과를 출력 할 때 대신 Id 값이 반환됩니다. 여전히 남아있다. 여기 내 스키마와 clearify하는 세부 코드, 감사문서를 반환하지 않는 채우기 메서드 - 채우기 메서드가 문서를 반환하지 않음 - 몽구스
var CommentSchema=new mongoose.Schema({
comment:{type:String},
accountId:{type:mongoose.Schema.ObjectId, ref:'Account'}
});
var StatusSchema=new mongoose.Schema({
comments:[CommentSchema],
accountId:{type:mongoose.Schema.ObjectId, ref:'Account'},//should be replaced with docement
status:{type:String}
});
계정 SCHEMA
var AccountSchema=new mongoose.Schema({
email:{type:String,unique:true},
password:{type:String},
name:{
first:{type:String},
last:{type:String},
full:{type:String}
},
contacts:[Contact],
status:[Status]
});
var Account=mongoose.model('Account',AccountSchema);
var Comment=mongoose.model('Comment',CommentSchema);
var Status=mongoose.model('Status', StatusSchema);
입니다 //이 내가
app.post('/accounts/:id/status', function(req, res) {
var accountId = req.params.id;
models.Account.findById(accountId, function(account) {
account.save(function(err){
if (err) throw err;
var status=new models.Account.Status();
status.accountId=accountId;
status.status=req.param('status', '');
status.save(function(err){
account.status.push(status);
account.save(function(err){
if(err)console.log(err)
else
console.log('successful! status save...')
});
});
});
});
res.send(200);
});
// QUERY - 난이 예상 새로운 댓글을 저장하는 방법입니다 쿼리를 사용하여 accountId를 참조 된 문서로 바꿉니다. 그러나 쿼리가 실행될 때 accountId는 참조 된 문서가 아닌 id를 계속 보유합니다.
var getActivity= function(accountId,callback){
Account.findOne({_id:accountId}).populate('Status.accountId').exec(function(err, items) {
console.log('result is:'+items);
});
}
을 내가 그냥'채우기 ('상태')해야한다고 생각'그것에 대해 – Benoir
덕분에, 여전히 thesame 결과를 데 –
문제가 계속 –