Quiz Database Schema for MongoDB

0
Users: [{
    - email
    - senha
    - quiz_criado: [id: 1], // ref: Quiz (array com id)
    - quiz_respondido: [{
        id: 1 , // ref: Quiz
        question_respondido: [{
            question_id
            opcao_escolhida
        }]          
    }] 
}]
Quiz: [{
    - quiz_id
    - nome
    - descricao
    - questions: [{
        - question_id
        - question_text
        - type // pode ser uma escolha ou multipla escolha
        - correct_anwsers // a resposta correta
    }]
}];

Quiz:

  • You will have all the Quizzes created by users.

Users:

  • You can create a Quiz or several Quizzes;
  • You can answer several Quizzes of other users.

Is it better to create everything in a Schema? Is there anything that can be improved in the schematic I created?

    
asked by anonymous 13.04.2017 / 17:58

1 answer

0

The design of the schema in Mongo should take into account the following question: How will you access the data?

Whereas you will list the quizes, without fetching the user it is best to use two same collections. It would not be interesting to fetch the user's data every time you're going to list the quizes. If it were a list of the user's favorites, for example, it would make more sense to incorporate.

One concern that may arise is about user responses. Asking the question I said at the outset: do I need all the answers from quizes when to load the user? Who knows at the beginning of the application this is not a problem, but after a while this list can get great. You could keep recent user responses on this list, and archive old responses in a separate collection. You could delete responses after a time interval (for this you would need a response date).

    
18.04.2017 / 02:04