Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:55:11+00:00 2026-05-26T14:55:11+00:00

I am new to MongoDB, but am looking at it to solve this problem:

  • 0

I am new to MongoDB, but am looking at it to solve this problem:

My application has a dynamic form builder that lets users create custom surveys, contact forms, etc. I want to log all of the form submissions and let the users who created the forms search through and export their submitted data.

I come from a typical PHP/mySql background, and see some challenges in storing this data in a mySql database. Each form could have any number of fields of all types. I would either need to normalize my DB to an EAV structure to store the data, or dynamically create a new table for each form, or serialize the form data into TEXT columns (ick).

The “schema-less” (or “dynamic schema”) nature of MongoDb seems like the perfect solution to my problem, but my n00b-iness leaves me unsure where to start.

  1. Should the results of each custom form be stored as separate collections?
  2. Should I have a “forms” collection, and embed the results as sub-documents for each form?
  3. Is there another, better way?
  4. Is MongoDb actually a good solution for this, or am I way off base?

To restate my problem one more time: I need to store data of variable and unknown structures in an easily searchable and sortable way.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:55:12+00:00Added an answer on May 26, 2026 at 2:55 pm

    I wouldn’t store results as embedded documents within the form document, since you may not know a priori how many submissions to expect. MongoDB limits each document to 16MB, but in practice you probably want to stay well below this threshold.

    Since your forms are variable, but pre-determined (that is, each form may differ but the forms are defined ahead of time in some sort of admin UI), I’d recommend using two collections:

    The first (call it forms) will store data about the makeup of each form: what fields, what types, in what order, etc. You could imagine documents in this collection would look something like this:

    { _id: ObjectId(...),
      name: "...",
      // other fields, for permissions, URL, etc
      fields: [
        { name: "username",
          type: "text",
          validation: { required: true, min: 1, max: null },
        },
        { name: "email",
          type: "text",
          validation: { required: true, min: 5, max: null, email: true },
        }
      ]
    }
    

    This lets you construct the forms dynamically (along with some server-side code) as needed for display in your application. It also gives information about what the fields are and what validation is required for them, which you can use during form submission. You’ll want an index on URL or whatever field you use to determine which form to display when serving web requests.

    The second collection, submissions or something, would store the submitted data for each form. Documents would look like:

    { _id: ObjectId(...),
      form: ObjectId(...), // the ObjectId of the record in "forms"
                           // that this is a submission on
      // other information here about the submitter:
      // IP address, browser, date and time, etc
      values: {
        username: "dcrosta",
        email: "dcrosta@awesomesite.com",
        //any other fields here
      }
    }
    

    If you need to be able to search by field-value pairs (or just values) in the submitted forms, a variation on this uses an array for the values field, like:

    { ...
      values: [
        { name: "username", value: "dcrosta" },
        { name: "email", value: "dcrosta@awesomesite.com" }
      ]
    }
    

    You can then create an index on the values field, and search like:

    // find "dcrosta" as username
    db.submissions.find({values: {$elemMatch: {name: "username", value: "dcrosta"}}})
    

    Or create an index on “values.value” and search like:

    // find "dcrosta" as value to any field
    db.submissions.find({"values.value": "dcrosta"})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to MongoDb but have an existing application which would benefit heavily
I have an application that lets users build things in JS. I want the
I'm new to rails and mongodb, and have a simple form attempting to create
This is from MongoDB docs : db.factories.insert( { name: xyz, metro: { city: New
I'm new and this is probably very trivial but I have the following method
I am new to mongodb and thinking of trying this out in PHP5. If
I'm considering using mongodb on a new project, but before delving in, I'd like
Coll.update(condition, new BasicDBObject($set, data), true, true)) This is my update query in mongodb for
So i am starting to make this new app that will be a software
I am creating an application that has several servers running at the same time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.