I am completely new to Mongo and RoR, coming from the background of PHP.
I just went through this data modeling tutorial http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails
and was amazed at the question of why the textbook would recommend storing votes in the field and updating this field as
db.stories.update ({_ id: story_id, voters: {'$ ne': user_id}},
{'$ inc': {votes: 1}, '$ push': {voters: user_id}});
instead
db.stories.update ({_ id: story_id, voters: {'$ ne': user_id}},
{'$ push': {voters: user_id}});
and then counting
Story.voters.count
to find out the number of users who voted?
I know this tutorial, but it doesn't seem like the most efficient way to manage data.
source share