Quiz Database Schema for Mongodb

Asked

Viewed 95 times

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 Quizzes created by users.

Users:

  • You can create a quiz or several quizzes;
  • You can answer several other users' quizzes.

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

1 answer

0

The schema design on Mongo should mainly take into account the following question: how you will access the data?

Considering that you will list the quizzes, without searching the user is better to use two Collections same. It would not be interesting to fetch user data every time you will list the quizzes. If it were a list of the user’s favorite quizzes, for example, it would make more sense to embed.

One concern that may arise is about the user’s responses. Asking the question I said at the beginning: I need all the quiz answers, 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 big. You could keep recent user responses on this list, and archive old answers in a separate Auditt. You could delete answers after a time interval (for that you would need a response date).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.