4 ms·
def 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
by sync 17y ago
def 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.