在 CouchDB 与 MySQL 中存储调查

发布于 2024-08-18 15:28:37 字数 3342 浏览 3 评论 0原文

我正在研究使用 Rails 将调查存储到数据库的最佳方法。我已经查看了这个很棒的 Smerf Survey Plugin for Rails ,它将调查存储到关系数据库中,其中包含以下内容表:


smerf_forms: name, code
smerf_forms_users: user_id, smerf_form_id, responses (as text)
smerf_responses: smerf_forms_user_id, question_code, response (as text)

查看 Smerf 附带的基本调查示例的日志,有一些数据库调用:


Processing SmerfFormsController#create (for 127.0.0.1 at 2010-01-24 20:09:58) [POST]
  Parameters: {"responses"=>{"g1q3a4s1"=>"", "g1q1a3s1a3s1"=>"", "g1q1"=>"1", "g2q1"=>{"1"=>"1"}, "g1q2"=>"2", "g1q3"=>{"1"=>"1", "2"=>"2", "3"=>"3"}, "g2q3"=>"12", "g1q4"=>["4"], "g1q5"=>["1", "3"], "g2q1a4s1"=>""}, "commit"=>"Press to Save your answers", "authenticity_token"=>"a4aDgvjzX0UK9HrQFdpdPyfALWGL22rcjRZfxDY3Ww0=", "smerf_form_id"=>"1"}
  SmerfForm Load (1.0ms)   SELECT * FROM "smerf_forms" WHERE ("smerf_forms"."id" = 1) 
  SmerfFormsUser Create (0.5ms)   INSERT INTO "smerf_forms_users" ("responses", "smerf_form_id", "user_id") VALUES('--- !map:HashWithIndifferentAccess 
g1q3a4s1: ""
g1q1: "1"
g1q1a3s1a3s1: ""
g1q2: "2"
g2q1: !map:HashWithIndifferentAccess 
 "1": "1"
g1q3: !map:HashWithIndifferentAccess 
 "1": "1"
 "2": "2"
 "3": "3"
g1q4: 
- "4"
g2q3: "12"
g1q5: 
- "1"
- "3"
g2q1a4s1: ""
', 1, -1)
  SmerfResponse Create (0.2ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q1')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('2', 1, 'g1q2')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g2q1')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q3')
  SmerfResponse Create (0.3ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('2', 1, 'g1q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('3', 1, 'g1q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('4', 1, 'g1q4')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('12', 1, 'g2q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q5')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('3', 1, 'g1q5')
Rendering smerf_forms/edit
Rendered smerf_forms/_smerf_form (11.0ms)
Completed in 51ms (View: 17, DB: 3) | 200 OK [http://localhost/smerf_forms]

我的问题是,使用 CouchDB(面向文档的数据库)而不是关系数据库来存储调查是否会更好,因为调查比其他任何东西都包含更多文档?沿着这些思路,有以下问题:

  • 上面的输出可以吗?是否应该进一步优化?我的意思是,人们不会不断地填写调查,所以他们不需要快如闪电,所以我想知道 CouchDB 是否真的会更快
  • 它已经用这个插件很好地构建了,所以我应该使用它还是在 CouchDB 中使用这个功能真的有好处吗?我想对这个调查数据进行大量分析(大量搜索、排序、加入......)。

感谢您的帮助。

仍在思考何时何地使用 CouchDB :)

I am looking into the best ways for storing surveys to a database with Rails. I have checked out this great Smerf Survey Plugin for Rails which stores surveys into a Relational Database with the following tables:


smerf_forms: name, code
smerf_forms_users: user_id, smerf_form_id, responses (as text)
smerf_responses: smerf_forms_user_id, question_code, response (as text)

Looking at the log for a basic survey example that comes with Smerf, there's a few database calls:


Processing SmerfFormsController#create (for 127.0.0.1 at 2010-01-24 20:09:58) [POST]
  Parameters: {"responses"=>{"g1q3a4s1"=>"", "g1q1a3s1a3s1"=>"", "g1q1"=>"1", "g2q1"=>{"1"=>"1"}, "g1q2"=>"2", "g1q3"=>{"1"=>"1", "2"=>"2", "3"=>"3"}, "g2q3"=>"12", "g1q4"=>["4"], "g1q5"=>["1", "3"], "g2q1a4s1"=>""}, "commit"=>"Press to Save your answers", "authenticity_token"=>"a4aDgvjzX0UK9HrQFdpdPyfALWGL22rcjRZfxDY3Ww0=", "smerf_form_id"=>"1"}
  SmerfForm Load (1.0ms)   SELECT * FROM "smerf_forms" WHERE ("smerf_forms"."id" = 1) 
  SmerfFormsUser Create (0.5ms)   INSERT INTO "smerf_forms_users" ("responses", "smerf_form_id", "user_id") VALUES('--- !map:HashWithIndifferentAccess 
g1q3a4s1: ""
g1q1: "1"
g1q1a3s1a3s1: ""
g1q2: "2"
g2q1: !map:HashWithIndifferentAccess 
 "1": "1"
g1q3: !map:HashWithIndifferentAccess 
 "1": "1"
 "2": "2"
 "3": "3"
g1q4: 
- "4"
g2q3: "12"
g1q5: 
- "1"
- "3"
g2q1a4s1: ""
', 1, -1)
  SmerfResponse Create (0.2ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q1')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('2', 1, 'g1q2')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g2q1')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q3')
  SmerfResponse Create (0.3ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('2', 1, 'g1q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('3', 1, 'g1q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('4', 1, 'g1q4')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('12', 1, 'g2q3')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('1', 1, 'g1q5')
  SmerfResponse Create (0.1ms)   INSERT INTO "smerf_responses" ("response", "smerf_forms_user_id", "question_code") VALUES('3', 1, 'g1q5')
Rendering smerf_forms/edit
Rendered smerf_forms/_smerf_form (11.0ms)
Completed in 51ms (View: 17, DB: 3) | 200 OK [http://localhost/smerf_forms]

My question is, would it be better to store surveys using CouchDB (a Document-Oriented Database), instead of a Relational Database, since surveys are more documents than anything else? Along those lines are these questions:

  • Is the above output okay, should it be more optimized? I mean, people won't be filling surveys out constantly so there's no need for them to be lightning fast, so I'm wondering if CouchDB would actually be any faster
  • It's already built nicely with this plugin, so should I just use it or would it be a real benefit to have this in CouchDB. I want to be doing a LOT of analysis on this survey data (lots of searching, sorting, joining...).

Thanks for the help.

Still trying to wrap my head around when and where to use CouchDB :)

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

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

发布评论

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

评论(5

孤城病女 2024-08-25 15:28:37

我强烈不同意 Sam 的评论:

  • 调查和调查回复是很好的文档示例。事实上,smerf 从磁盘上的 YAML 文件加载表单定义,尽管我对 smerf 一点也不熟悉,但我猜测 smerf_forms_users.responses 是一组序列化的答案。
  • 面向文档的数据库并不意味着数据不能被分析。 CouchDB 和 MongoDB 都有提取和分析隐藏在文档深处的信息的机制。

另请注意,通过将表单定义序列化为 YAML,问题和答案之间无论如何都不会留下任何联系,因此可以说它不是一个关系解决方案。 (如果我为此使用 RDMBS,我会做完全相同的事情 - 想象一下架构!)

在面向文档的数据库中,很可能包含调查文档(每个调查一个)和调查响应文档(每个调查每个用户一个) 。简单干净。

然而,尽管我认为文档数据库很合适,但我确实同意托比的评论,即如果农奴可以使用它,而不是增加额外的复杂性。

至于哪个最好 - CouchDB 与 MongoDB - 这部分是个人喜好,部分是需求。

I strongly disagree with Sam's comments:

  • A survey and a survey response are great examples of documents. In fact smerf loads the form definition from a YAML file on disk and, although I'm not at all familiar with smerf, I'm guessing smerf_forms_users.responses is a serialised set of answers.
  • A document-oriented database does not mean data cannot be analysed. CouchDB and MongoDB both have mechanisms for extracting and analysing information buried deep inside the documents.

Also, note that by serialising the form definition to YAML there is no connection left between the questions and the answers anyway so it's arguably not a relational solution. (I would do exactly the same if I was using an RDMBS for this - imagine the schema!)

In a document-oriented database there would most likely by survey documents (one per survey) and survey response documents (one per user per survey). Simple and clean.

However, even though I think a document database would be a good fit, I do agree with Toby's comment that if serf works use it rather than adding additional complexity.

As for which is best - CouchDB vs MongoDB - that's partly personal preference and partly requirements.

雨巷深深 2024-08-25 15:28:37

调查不是文档,它们是带有多组答案的问题的集合。关键点是,当您进行调查时,您不想只存储结果,而是要分析它们。如果将结果视为单个文档,则会导致分析变得困难。将数据存储在关系数据库中将简化分析。

Surveys are not documents, they are a collection of questions with many sets of answers. They key point is when you run a survey, you don't want to just store the results, but analyze them. If you treat the results as a single document, it will make analysis difficult. Having the data in a relational database will simplify analysis.

大姐,你呐 2024-08-25 15:28:37

调查非常适合文档数据库。主要要问自己的是:“将其存储为 JSON 会让我的生活更轻松吗?”

Meebo 使用 CouchDB 进行调查回复等。他们在 CouchDB-Lounge 集群中存储了 1.6 亿多个文档。

@Toby - 这是一个权衡的问题。借助 CouchDB,您可以获得经过验证的可靠性和可扩展性,以及任何其他数据库都无法比拟的复制功能,而且这一切都是通过 HTTP 实现的。使用 MySQL 或 Mongo,您可以为少数用户快速获得结果,以及某种形式的自动索引/查询规划。

Surveys are great fit for document databases. The main thing to ask yourself is: "would storing this as JSON make my life easier?"

Meebo uses CouchDB for survey responses among other things. They store 160+ million documents in a CouchDB-Lounge cluster.

@Toby - it's a matter of tradeoffs. With CouchDB you get proven reliability and scalability, replication that's not matched by any other database, and it's all via HTTP. With MySQL or Mongo you get fast results for a few users, and some form of automatic indexing / query planning.

宛菡 2024-08-25 15:28:37

如果调查插件现在可以使用,我会按原样使用它。

向您的应用程序添加另一个数据库系统将引入大量额外的工作……开发时间,以及部署和系统管理。

除此之外,我只是认为 CouchDB 不如某些替代方案......我发现 MongoDB 更快、更有用(即席查询实际上可以开始使用)。 MogoDB 现在也有一些优秀的 Rails 支持库。

If the survey plugin works now, I would use it as is.

Adding another database system to your app will introduce a lot of extra work ... development time, plus deployment and system administration.

On top of this, I just don't think CouchDB is as good as some of the alternatives ... I have found MongoDB to be faster and more useful (ad-hoc queries that actually work for a start). MogoDB also has some outstanding support libraries for Rails now.

农村范ル 2024-08-25 15:28:37

Zodiac.NET 是存储调查的一个很好的例子。它使用 XML 进行调查定义:

http://www.mentor-logic .com/index.php/products/components/zodiacnet

Zodiac.NET is a good example of storing the surveys. It use XML for survey definition:

http://www.mentor-logic.com/index.php/products/components/zodiacnet

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