Вопрос

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?

Это было полезно?

Решение

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?

Другие советы

Not a full answer, but a link to a good voting library (fast!!!) for ruby/mongoid. Should be easily portable to node.js, perhaps mongoose.

https://github.com/vinova/voteable_mongo

I need something similar eventually, perhaps we should chat (I am martin_sunset on node.js on freenode)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top