【发布时间】:2014-10-02 10:44:29
【问题描述】:
var Poll = mongoose.model('Poll', {
title: String,
votes: {
type: Array,
'default' : []
}
});
我的简单投票具有上述架构,但我不确定更改投票数组中元素值的最佳方法。
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.
});
});
【问题讨论】:
标签: node.js mongodb mongodb-query