0
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.
});
});