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

300
Views
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
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!