I'm quite new to Meteor and I'm trying to figure out how to implement some use cases. One of them is an application for polls. Let's say you have a couple of users that can vote on a couple of polls (for simplicity let's assume polls are limited to yes/no questions). Each use can only vote once.
In SQL I would normalize this in 3 tables:
USER (id/name)
VOTES (user_id/poll_id/choice)
POLLS (id/question)
However in the document-store world of mongodb, it seems encouraged to store the votes in a collection with the polls, like so:
[
{
_id: 1234
question: "the question"
votes:
[
{
user_id: 1
choice: 1
}
]
}
]
If a user votes on a poll an item gets inserted in the votes array of a poll. The server side has to validate the user has not already voted. To get the total score I have to iterate over the votes, but of course that could be improved by creating a field on each poll that contains the aggregated score, which gets updated as votes are added.
However, how does this propagate to other users? Let's say a vote is added to a poll. Does the entire poll object get send over to other connected clients? Because if a lot of people or voting, the votes array can get big and will cause a lot of traffic...
But in that case, when the admin user changes the question (and therefore writes a new version of the poll object to the collection), either the update query needs to know it only should update selected fields. Or if overwriting the entire object the admin user should have the latest version of the object (since meteor is last-write-wins).
Am I missing some best practices around this or is it indeed easier to model my collections the same way I would model a normalized SQL DB?