Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Scalable voting system with MongoDB

Scalable voting system with MongoDB

Problem

This article explains very clearly how to implement a voting system with MongoDB, and to limit one vote per user and per object.

I have one extra requirement. I need the votes of a given user to be visible for the objects displayed. For example, if I am displaying 20 tweets, and the user has voted on 3 of those tweets, I want those votes to be visible. (For example, using a green up-arrow.)

One Solution is to send to the client, for each question, the set of voters. Another solution is to send to the client the set of votes he has cast. I do not see either solution as a scalable one. Any suggestions?

Problem courtesy of: Randomblue

Solution

This is something you would do client side.

Once you have the object that contains the vote cound and the array of voters you can check to see if the current user's id is within the array of voters while you iterate over the set of (stories, tweets, what have you)

Does that make sense?

Solution courtesy of: Tyler Brock

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Scalable voting system with MongoDB

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×