I have a web application using a relational database (MySQL). We are adding a new feature that will allow certain users to dynamically create โformsโ from a pool of optional form elements and distribute these forms for completion / submission to other users.
The problem is storing the completed forms. Each form can and will vary in the number and combination of form elements, and with a relational database my parameters are somewhat limited by dynamically creating a new table to store representations of each form (it seems that this is a bad way to go) or to store each of the submitted forms as JSON in TEXT column (losing all the useful features of RDBMS queries)
I had never used MongoDB in a production project before, but I think it would be nice to use my MySQL relational database to store all forms created by certain users of my application, and then save all the views in MongoDB with every document referencing the form's UUID in MySQL.
The first drawback that I can come up with with this approach is the lack of referential integrity between the form submissions and the forms hosted in MySQL. If I delete the form in MySQL, all forms must be deleted manually (if I want to replicate the Cascade effect)
Will I store all my forms for all my forms in one MongoDB collection as separate documents? Any advice is much appreciated. :)
EDIT 1 Based on the documentation here: http://www.mongodb.org/display/DOCS/Using+a+Large+Number+of+Collections
Now I am considering the possibility of creating a new collection to store all views from each unique type of form.
EDIT 2
After some careful consideration and recommendations of others, I decided to abandon my approach with two databases to solve this problem in favor of a relational database scheme, which, I think, solves the problem of creating dynamic forms and saving forms in such a way that they can easily handle queries for complex reports.
Essentially, each entry in 'forms' is a unique form created by the user. 'forms_fields' has a foreign key that refers to the form and type of the enumeration with parameters: 1. checkbox 2. text field 3. textarea 4. select 5. multi-select 6. date
'forms_fields_options' contains all the "parameters" that will have a selection field. Using these three tables, users can create custom forms.
When another user fills out and submits the form, an entry is created in forms_submissions. For each field, a corresponding record will be created in 'forms_submissions_fields', which refers to the form view and form_fields_id. The summary table, 'forms_submissions_options_multiselect', is essentially a connection table that indicates which parameters from the multiple choice form field the user has selected.