Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
Best method to keep track of a users progression through reading sections of text

Similar to zyBooks if you are familiar with it, I want to track the sections the user has read through and checked completed with a button.

However, conceptually I am having trouble thinking of what to store in my mongo database, besides just an object or an array of objects that contains each section and bool values, to track their progress. A section will have around 10 subsections. But there will be around 8 sections total. So a total of 80 subsections to keep track of.

This is what I was thinking of but it seems inefficient.

const sectionArray = [
  {
    section: "1",
    completed: false,
    subsections: [
      {
        name: "1.1",
        completed: false,
      },
      {
        name: "1.2",
        completed: false,
      },
      {
        name: "1.3",
        completed: false,
      },
    ],
  },
  {
    section: "2",
    completed: false,
    subsections: [
      {
        name: "2.1",
        completed: false,
      },
      {
        name: "2.2",
        completed: false,
      },
      {
        name: "2.3",
        completed: false,
      },
    ],
  },
...
];

I will also display a section and its subsections content depending on which the user decides to view using react and material ui.

I do not want to commit to my method if there is a better alternative.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think your approach is totally fine with that amount of data.

The question is, what do you mean with "inefficient" ?

From a performance point of view, 80 elements are just no problem. Maybe you just don't feel well with handling that code (which is a valid reason).

An alternative would be:

const sectionArray = [
  { section: "1", completed: false },
  { section: "1.1", completed: false },
  { section: "1.2", completed: false },
]

or (quicker access of the sections, e.g. without a .find()):

const sectionCollection = {
  "1": false,
  "1.1": false,
  "1.2": false,
]

Maybe you don't need to store the main sections, if they are implicitly done when all sub sections are done ?

const sectionCollection = { 
  "1.1": false,  // "1" is implicitly done if all "1.x" are done
  "1.2": false,
]

Probably not an appropriate alternative (would be more efficient if most items are likely always false):

const sectionArray = [ "1", "1.3", "3.2" ] // 1, 1.3, 3.2 are 'true', all others are 'false'

Just for fun: You might also use integers as section IDs (which is ridiculously over optimizing on the wrong end):

const sectionCollection = [ 100, 103, 302 ]    // list of integers
const sectionCollection = [ 0x10, 0x13, 0x32 ] // using hex or bin
const sectionCollection = { [100]: false, [101]: true } // integer keys

And then even store a Byte array instead of JSON.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda