System Information
-
Strapi Version:
-
Operating System:
-
Database:
-
Node Version:
-
NPM Version:
-
Yarn Version:
How to remove the duplicate entries in a collection type while importing the data.
if i import two to three times its creating duplicate entries ,so is there any way to remove the duplicate entries before importing
@Arun_Jenson Which plugin are you using for importing data. Is it a strapi plugin or your custom build import plugin?
If it is custom, while using data import you can check whether the row data exists or not, if it exists then update it or else delete it and create a new entry.
im using my custom build import controller, can you provide an example for your approach
I do not have a solid example for custom import feature, but what I have suggested you was a logical explanation.
When you import the data for the first time, they will be saved in a collection with record details.
When you reimport the data again, you have to check whether the row exists in particular collection or not by using
let recordExists = strapi.db.query(‘api::collection-name.collection-name’).findOne({
where: { id: $row[‘id’] }
})
If the query finds an existing record, you have to update that particular record and if it doesn’t exists then create a new one.
I hope this explanation would be clear to you.