Hi there,
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 :)