Avoid duplicates when using repeaters with database

I am using a database to store information on books, and I have a repeater that contains buttons to link to a dynamic page for each author, where all books with that author are dynamically linked to in a gallery. I want this repeater to dynamically update whenever I add a book with a new author.

The problem is if I have more than one book with the same author the repeater will show them multiple times (each of these duplicate buttons leads to the same dynamic author page). How can I make there be only one repeater container per author?

Hey
Answered before but what you do is to use reduce when setting the data to your repeater.

$w("#repeater1").data = Array.from(results.items.reduceRight((m, t) => m.set(t.title, t), new Map()).values()).reverse();

Just remeber to use the correct fieldkeys.

2 Likes

sorry, I have not used code before, just databases. Can I please have some more context on how to use this?

Well paste your code you have here and if no code send name on dropdown.

hi I know this was ages ago but I’m having the same problem as this person, please could you help me. I have no code but don’t mind copying and pasting. Can you help me?

I’m having the same issue. Could you please help me on this.

ISSUE HERE - This is a dynamic page which is loaded after a button click (so the data is already filtered being a dynamic page). Now that data is already filtered, I want to remove duplicates. The code below is removing duplicates from the database import but I want to remove duplicates from the filtered data in the repeater.

Bold ones are variables - varying as per my collection/usages.

CODE HERE -
import wixData from ‘wix-data’;
export function dataset _ready() {
wixData.query(" databasecollection “).limit(1000).find().then(results => {
$w(” # repeater ").data = Array.from(results.items.reduceRight((m, t) => m.set(t. myfieldkey , t), newMap()).values());
});
}

Please connect on this, Thanks!
Looking something like onreadyitems in the repeater were data is already imported/filtered and now applying wix code for removing duplicates.