Hi;
I add csv files to my wix database, since the number of records is high, I cannot delete or compare them one by one.
I transfer the data in the csv file that I update everyday. But I do not want to reload the data I transferred the previous day. Each record must be unique.
Do you have a sample code? such as automatic deletion of duplicate records or ignoring file upload
I’m trying the two codes below but I couldn’t. Where’s my fault? How should I do a sample code or educational video about it?
I want to prevent repeated records in the database. It is not possible to manually check or delete the CSV file every day, since there will be more records in the file, which will contain repetitive records every day. Please help with this.
Thank you
Note: The column where I check the duplicate records is the original link url address / column with url content.
reference column for comparison : OriginalConnectionDetails
(By comparing url addresses, I do not want to add the existing record back to the database while transferring the csv file if it was added to the database before.)
Database : Germany
Example Code-1
import wixData from ‘wix-data’; export function searchForDuplicates(value) { return wixData.query(“Diamond”) .eq(“giaCode”, value) .find() .then((results) => { return results.items.length; }) .catch((err) => { let errorMsg = err; }); } export function Diamond_beforeInsert (item) { return searchForDuplicates(item.giaCode).then((res) => { if(res > 0) { return Promise .reject(“Duplicate”); } return item; }); }
-------- Example Code-2
import wixData from ‘wix-data’ ;
export function searchForDuplicates(collection, field, item) {
// info contains the hook context
// use the collectionName property to use function for multiple collections
return wixData.query(collection)
.eq(field, item[field])
.find()
.then((results) => {
return results.items.length;
})
. catch ((err) => {
let errorMsg = err;
});
}
export function Germany_beforeInsert(item, context) {
// Calls routine to check if value already exists in the collection.
// If value not found, then save record.
// Else, if value is found, then reject this insert to prevent duplicate values.
// Note: concurrent inserts may result in duplicates.
// Pass context to searchForDuplicates to use for multiple collections.
return searchForDuplicates(context.collectionName, “OriginalConnectionDetails” , item).then((res) => {
if (res > 0 ) {
return Promise.reject( ‘This item already exists’ );
}
return item;
});
}
#database duplicate #csv #csvimport #databaserecorddelete #delete #duplicatedelete