Polling app, multiple checkboxes/cateogries per document


#1

Hi,

I’m creating an app where several logged users vote on different topics. Each topic can belong to up to five categories. The idea is that a user can check, for each topic, if it belongs to one or more of those categories.

This will be done live with every user in the same room, so they each vote their preferences on their own device, but also see in realtime the aggregated sum of everybody’s votes on each category per topic.

The admin view (the one being displayed on the big screen) will show the list of topics along with how many votes each category has for each topic.

My challenge so far is not code-wise, but how to better structure the data and collections, to simplify data gathering from multiple users into a single view

Should I for example have a separate collection for topics with vote count as an array, and then another one for each user where I store user’s preferences? Or rather embed all data into fewer collections? Maybe like this?

// Collection for every Topic
{
    {
    "_id": "LTA5BkNmn72cjNnWD",
    "topicName": "My First Topic"
    },
    {
    "_id": "BFD2SkNmn72cjNnR3T",
    "topicName": "My Second Topic"
    }
}

// Register and add Votes for each category within each Topic
{
 	{
 	    "topicID": "LTA5BkNmn72cjNnWD",
	    // Vote count every user's opinion
            "observe": 3,
	    "understand": 8,
	    "create": 2,
	    "prototype": 0,
	    "validate": 0
	  },
    {...}, 
    {...},
}

// User Preference
{
    "userName": "Sergio",
    "userVotes": {
	[
	 {
	   "topicID": "LTA5BkNmn72cjNnWD",
           // just this user's opinion
	   "observe": false,
	   "understand": false,
	   "create": true,
	   "prototype": true,
	   "validate": false
	  }
	 ],
	 [...],
         [...]
    }
}