使用 MongoDB 的可扩展投票系统
这篇文章非常清楚地解释了如何使用 MongoDB 实现投票系统,并限制每人一票用户和每个对象。
我有一项额外要求。我需要给定用户的投票对于显示的对象可见。例如,如果我显示 20 条推文,并且用户对其中 3 条推文进行了投票,我希望这些投票可见。 (例如,使用绿色向上箭头。)
一种解决方案是针对每个问题向客户端发送一组选民。另一种解决方案是将他所投的选票集发送给客户。我认为这两种解决方案都不是可扩展的。有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您在客户端要做的事情。
一旦你有了包含投票数和选民数组的对象,你就可以在迭代一组(故事,推文,你有什么)时检查当前用户的 id 是否在选民数组中
。感觉?
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?
不是完整的答案,而是一个指向 ruby/mongoid 的良好投票库(快!!!)的链接。应该很容易移植到node.js,也许是mongoose。
https://github.com/vinova/voteable_mongo
我最终需要类似的东西,也许我们应该聊天(我是 freenode 上的 node.js 上的 martin_sunset)
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)