var Poll = mongoose.model('Poll', {
title: String,
votes: {
type: Array,
'default' : []
}
});
간단한 설문 조사에 위의 스키마가 있으며, 투표 배열의 요소 값을 변경하는 가장 좋은 방법은 확실치 않습니다.Mongodb, 배열 내부의 값을 증가시킵니다. (save()? update()?)
app.put('/api/polls/:poll_id', function(req, res){
Poll.findById(req.params.poll_id, function(err, poll){
// I see the official website of mongodb use something like
// db.collection.update()
// but that doesn't apply here right? I have direct access to the "poll" object here.
Can I do something like
poll.votes[1] = poll.votes[1] + 1;
poll.save() ?
Helps much appreciated.
});
});