I recently finished the voting app and am now beginning planning for the nightlife coordination app. I’ve been using Mongoose for back-end database storage, and I had a general question on how to store things like votes/likes/claps/etc.
In the voting app, I wanted to make sure that a user could not vote twice. I did this by storing (in Mongoose) for each poll, an array consisting of usernames of who already voted. Then, when it was time to process a user clicking on “vote”, I took the username and compared it with the entire array of usernames who already voted. If I got through the array without a username match, then I would tack my username at the end of the array. If I got a username match within the array, then I would stop and return an error that I’m not allowed to vote.
This was fine for a small app, but I feel that when there are thousands of votes that this is not the best idea because I have to check through all of them before a user gets to vote. How should I organize things to solve this problem?