[Solved] Code to check for duplicates in database and only displaying the newest on repeater (based on updated date)

When you say “it seems not to work”, are you basing it on examining the results of the aggregate and the query in the console?

There’s so much I don’t know about what you’re doing. My reason for posting was simply to introduce an approach for identifying the duplicates and showing the newest. The second query should return all of the records in that collection where owners were multiple times in one location, and that would include the newest one. Your code would have to loop through the results and figure out which ones are the older ones that you don’t want to show on the page in question.

I think that flagging the “old records” that you don’t want to show would be the way that I would choose to approach it because then when the page loads it’s just a simple matter of filtering those out based on that field’s value. If you do it that way, then the challenge is to figure out what point in your code would be the ideal place to fire the code that flags those records? If you can catch it at the point when you’re creating a new record for a particular owner at a particular location, that would be ideal. If you could somehow flag all the older records of that same owner at that same location at that point, that might be the easiest. Again, this is a suggestion based on not knowing everything involved.