Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
Filtering duplicate key/values across an array of objects

I have a MongoDB collection set up with the following document schema. Each document represents one "run" on a ski slope.

MongoDB screenshot

In the app, I'm using a forEach to loop over each document based on resortName and date to create HTML cards. Unfortunately, when I add multiple documents on the same date (i.e: someone does multiple runs on the same date) it creates another HTML card rather than one card for each unique date present.

My thought is to loop over the entire collection and remove documents if a particular date is already present. My attempt to do this is in the EJS template is below:

The collection in question is referenced as dates.

  <% const uniqueValuesSet = new Set() %>

  <% const filteredArr = dates.filter((obj) => { %> 
  <% const isPresentInSet = uniqueValuesSet.has(obj.date); %>
  <% uniqueValuesSet.add(obj.date); %>
  <% return !isPresentInSet %> 
  <% }); %>
  
  <% console.log(filteredArr)%>

Unfortunately, this is not actually removing anything and console.log(filteredArr) is returning the entire collection - no different than console.log(dates).

**Edit: I have been referencing this

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda