I have a MongoDB collection set up with the following document schema. Each document represents one "run" on a ski slope.
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