2014-04-13 2 views
2

중첩 배열 속성이있는 배열 속성이있는 몽구스 모델이 있습니다.배열 스플 라이스 후 몽구스 모델 저장 안 함

self.findByCustomerId(customerId, function (err, order) { 
    if (err) done(err, null); 
    console.log('Toppings before splice: ',order.lines[lineIdx].toppings); 
    order.lines[lineIdx].toppings.splice(toppingIdx, 1); 
    order.updated = new Date(); 

    // NOTE: This line causes the order.save to work 
    order.markModified('lines'); 

    order.save(function (err) { 
     if (err) done(err, null); 
     console.log('Toppings after splice: ',order.lines[lineIdx].toppings); 
     done(null,"OK"); 
    }); 
}); 

그래서 모든 것을 완벽하게 작동하지만 있습니다 ... 다음 코드 쇼의 console.logs 정확히 내가 기대하고있어 데이터는, 그러나, 데이터가 데이터베이스에 유지되지 않습니다 내가 왜 단서가 없다 최종 데이터베이스 지속성 비트. 내가 뭘 놓치고 있니?

도움을 주셔서 감사합니다. 나는 분실했습니다.

+0

'order'에 대한 스키마를 포함하도록 질문을 업데이트 할 수 있습니까? – JohnnyHK

답변

3

order.markModified ('lines')가 필요합니다. 원래 게시물에 코드를 추가했습니다. 이를 추가하면 모델이 올바르게 저장됩니다.

+0

답변을 수락해야합니다. – aymericbeaumet