如何存储CouchDB文档的投票?

发布于 2024-10-05 14:37:00 字数 313 浏览 0 评论 0原文

我正在寻找一个如何在文档中存储投票的好例子。 例如,如果我们有一个已发布的文档,并且用户可以对其进行投票。 如果我将投票存储在文档中的某个字段中,例如:

votes : 12345

如果作者正在编辑帖子,并且在此期间有人投票,会发生什么情况?作者将无法保存,因为有人投票并且文档将进行新的修订。

另一种选择是单独存储投票,将每个投票作为文档,或者为每个帖子创建一个包含投票的文档?

如果我决定将每张投票存储在不同的文档中,聚合这些数据会有多困难?或者我每次展示文档时都必须计算它?

你们的解决方案是什么?

问候

I am looking for a good example how to store votes in a document.
For example if we have a document which is post and users can vote for it.
If I store the vote in a field in the document, for example:

votes : 12345

What will happen if the author is editing the post and during this time someone votes? The author is not going to be able to save, because somebody voted and document will be with new revision.

The other option is to store votes separately, each vote to be document, or to create a document with votes for every post?

If I decide to store every vote in a different document, how difficult it's going to be to aggregate this data? Or I have to calculate it each time when I show the document?

What are your solutions?

regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2024-10-12 14:37:00

这会导致冲突。 CouchDB 指南中有一个章节是关于处理冲突的。
http://guide.couchdb.org/draft/conflicts.html

如果您使用中间件(例如PHP)它可以识别并处理冲突。 (参见 wiki 示例代码:http://wiki.apache.org/couchdb/Replication_and_conflicts

如果您想提供纯 CouchApp,则应该可以使用更新处理程序来自动管理一些常见的冲突情况。 http://wiki.apache.org/couchdb/Document_Update_Handlers

如果它有效,我更愿意存储文件中的投票。但我自己还没有尝试过这些方法。所以如果您分享您的解决方案,我会很高兴。

This will result in a conflict. There's a chapter in the CouchDB Guide about handling conflicts.
http://guide.couchdb.org/draft/conflicts.html

If you use a middleware (such as PHP) it can recognize and handle the conflict. (see wiki for example code: http://wiki.apache.org/couchdb/Replication_and_conflicts)

If you want to offer a pure CouchApp it should be possible to use update handlers to manage some common conflict cases automatically. http://wiki.apache.org/couchdb/Document_Update_Handlers

If it works I would prefer to store the votes in the document. But I did not try any of these approaches for myself yet. So I would be happy If you share your solution.

凡尘雨 2024-10-12 14:37:00

我发现这篇文章对于当许多用户更新文档(例如投票或向博客文章添加评论)时如何避免冲突的主题非常有帮助。

http://www.cmlenz.net/archives/2007/10/couchdb-joins

第三个也是最好的(?)解决方案是将每个评论存储为一个单独的文档,并带有博客文章的链接。使用复杂的键可以非常轻松地查询属于某个帖子的所有评论以及查询用户发表的所有评论,甚至可以按时间顺序排序。

I found this article to be very helpful on the subject of how to avoid conflicts when many users will be updating a document, such as voting or adding comments to a blog post.

http://www.cmlenz.net/archives/2007/10/couchdb-joins

The third and best(?) solution was store each comment as a separate document with a link to the blog post. Using complex keys made it very easy to query for all comments belonging to a post as well as querying for all comments made by a user, even sorted in chronological order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文