Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!