Trying to not display database duplicates in repeater

I want to connect a repeater to my database, showing the available categories I have on my website. I have duplicates in my database, and want to try and find a way to not display any duplicated category in my repeater.

Can anyone help? Thanks.

Hello Jamel

you can use that using code, add a function to prevent the duplicates:

  • Query the the collection and Get the resulting array for the field you want to connect to (for example let’s items)
    -Define a new array ( let uniqueItems = )
    -loop over items and push in unique items values that haven’t been pushed before
//results is an array of items that has all the values in the collectionwill 
let results = wixData.query("myCollection").find()

//items is an array of result items
let items = results.items

//empty array to push unique items
let uniqueItems =[]

//prevent duplicates
await items.forEach(async (item) => {
       if (uniqueItems.includes(item.fieldkey) === false) {
         await uniqueItems.push(item.fieldkey);
       }
 })
 

Best
Massa

@yisrael-wix Hi, Sorry, I didn’t mean to hijack. In fact I was using the above to accomplish some of my requirements and it immediately showed some error and hence I was asking if there is any mistake in the code or if I was doing it wrong. That was my actual question. I just mentioned my other question on this thread thinking that it won’t break the community guidelines. Also, one of the reasons I mentioned that here is because most of my question on this forum is not answered.

Not to mention, your ( Yisrael, this is the first user I noticed on this forum) answers on this forum to many questions asked by users like me has helped me a lot in learning and coding Corvid. Your answers on this forum and other’s posts and videos are my learning resources. Unfortunately many of my questions on this forum did not get any reply.

NOTE: I am a beginner, started coding Corvid since just a few days.

@learnuntildie

Please add yours as a new forum post so that you can get help with your own issue and add a link to refer back to this previous post if needed.

Also add to this new post all the code that you have used for your own page so that we can see what code you have, along with any screenshots that you think will help.

Please add your code in a code block so that it is easier to read and work with.

Make use of the forum search as you can find other posts that might help you like these ones here.
https://www.wix.com/corvid/forum/community-discussion/repeater-databases-duplicates
https://www.wix.com/corvid/forum/community-discussion/removing-duplicates-in-a-list
https://www.wix.com/corvid/forum/community-discussion/removing-duplicates-in-the-dynamic-page-repeater-were-the-repeater-is-already-filtered
https://www.wix.com/corvid/forum/community-discussion/avoid-duplicates-when-using-repeaters-with-database

Always best to make a new post instead of bumping up an old thread as it might not be correct or suitable for your actual needs.

Plus old posts might sometimes contain old and outdated code too that has been updated or deprecated, or a new API has been introduced and you can use that instead for example.