Okay so I am making a polling website. There are basically two ways to vote. Simple vote which just counts the number of votes for a movie. And ranked voting where each user ranks each movie and then the winner is decided using instant runoff. Here is my idea of how to handle it: I have a poll collection which just stores the rank for each movie for ranked polls and number of votes for each movie for simple. So something like this:
{
_id: ObjectId
pollType: string
movies: array
0: Object
id: ObjectId
title: String
rank: number
votes: number
}
Then I have a vote collection which a vote is added each time a user votes.
{
_id:ObjectId
pollId: Objectid
votedMovies: Array
0: Object
id: ObjectId
title: string
rank: number
}
When the user votes I will then retrieve all the votes for a poll and for simple votes increment the vote count based on what movies where in the votedMovies Array. For ranked voting I would get each movie rank for every vote and then do a instant runoff calculation. Finally I would then update the polls votes and rankings for each movie. Am I thinking about this correctly? Is there ways I could improve or simplify my design? Thanks for any guidance.