Custom Polling App - User generated options

Hi,

We’re building a polling app where the user can create their own poll, and then create multiple questions as part of their poll. The user will be able to add their own options to each question. There will also be different question types, such as “Which picture do you prefer?” or multiple text options.

We just wanted to see how others would structure this. We have a collection that contains the polls, and a separate collection that contains the questions. The poll id is logged in each question.

The challenges are:

  1. Multiple question types, potentially with different outputs
  2. User can add a custom number of answers / options for the poll

If anyone can point us to any resources on this, or offer any advice or ideas on structuring, we’d be very grateful!

1 Like

I actually just finished implementing something very similar for a client. I have a collection for Questions, but recommend having a separate collection for things like Checkbox/Radio selections (instead of embedding arrays in Questions like I did, major PITA) depending on how you structure the Polls.

How mine works is, if a user initiates a Poll, a new Poll document will be created for him, with questions copied over from the Questions collection. So that if the Questions get edited, it will not get updated for him while he is filling out the Poll, unless he deletes it and starts over.

Here’s what my UI looks like if it helps any (yours would be for editing Poll Questions):
elvellonmvp

Like hellstad said, putting arrays that will change in your documents is a pain. We have the following structure:

Surveys -> Pages -> Questions -> Choices (optional)

The Questions have properties for question type and optional information depending on the type (min/max/longText/shortText/etc.) When it’s time to display the question we render a template based on the question type. There’s a template for each question type and it knows how to render that type of question.

As for images, we require each choice to have a text to describe the image. You can’t include the images in most tabular reports.

This is what we did: responses.me. It might give you some ideas.

Hope this helps.

Thanks for your reply, I thought the whole array way of doing things would be a pain!

What method are you using to pull the questions over when the user starts the poll?

Thanks Manuel, this is really helpful!

Do you have a seperate collection that contains the options, and then add the ID to the document in the question collection?

I thought this might be the best way to work in terms of reactivity, but thought it could get complicated quickly! Is performance an issue for you using this method?

I fetched a copy of all the questions and pushed it into the newly created application (or poll in your case). This creates an embedded array, but the first level is not that bad to deal with. It’s the embedded array within the questions that makes mine hard to update.

Meteor.methods({
newApplication: function (fc_name) {
        check(fc_name, String);
        if (this.userId) {
            // try find: application belonging to current user, that is not submitted yet
            if (!Applications.findOne({owner: this.userId, submitted: false})) {
                var appQuestions = RecruitmentQuestions.find({fc: fc_name, published: true}).fetch();
                return Applications.insert({
                    owner: this.userId,
                    fc: fc_name,
                    dateCreated: new Date(),
                    questions: appQuestions,
                    submitted: false
                });
            } else {
                return Applications.findOne({owner: this.userId, submitted: false})._id;
            }
        }
    }
});

Yeah (we call it Choices though). Each record has all parent keys. That is, questions have pageId and surveyId; choices have questionId, pageId, surveyId. It makes life a lot easier.

As for performance, we don’t have server side rendering performance but it’s good enough.