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

314
Visualizações
Mongoose best way to store a set of ids in a document? Map? Array?

I have a table Entries where each document represents a list entry. Among other info, I want to store a set of id's in each document. These id's will be strings. The relevant id's needed will vary between different documents. When these documents are retrieved, the goal is to be able to efficiently display the entries in a React table and filter by the id's each document has, which seems like would make the most sense as a javascript Set.

Example of what I'm thinking of:

{
  name: "Bob",
  ids: {
    "1234a",
    "9999b"
  }
},
{
  name: "Paul",
  ids: {
    "9999b",
    "0000z"
  }
}

From reading around, it looks like I could potentially store ids as an Array, and convert them to a Set when retrieved.

Another options seems to be to store ids as a Map, where the key is the id and the value is something arbitrary (like true or something). Example:

{
  name: "Paul",
  ids: {
    "9999b": true,
    "0000z": true
  }
}

What would be the most performant way to do this?

about 4 years ago · Juan Pablo Isaza
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