3 ms·
How do you track views? Are you doing a DB write on each question view?
by JeremyChase 17y ago
How do you track views? Are you doing a DB write on each question view?
- cheald 17y agoMongoDB is extremely well-suited to this sort of thing. In-place increments/decrements are particularly easy to do.
- sync 17y agodef viewed! self.collection.update({:_id => self._id}, {:$inc => {:views_count => 1}}, :upsert => true) end Not sure why it's an upsert, but there's your answer -- atomic increment.