how could I avoid a duplicate in array, I'm looping the array I receive, and I need to save in mongodb, so it's duplicating the array's indexes, maybe using a filter I thought, wouldn't it be harmful to the system maybe?, and how could in this case use a filter to filter duplicates in an array with a structure that has objects, strings, etcs
const hasDate = await Universities.find({country})
if(hasDate.length > 0) {
return new Error('Dados já existe');
} else {
for(let i in returnApi) {
await Universities.create({
domains: returnApi[i].domains,
alpha_two_code: returnApi[i].alpha_two_code,
country: returnApi[i].country,
web_pages: returnApi[i].web_pages,
name: returnApi[i].name,
state_province: returnApi[i].stateprovince
})
};
await insertNameUniversities(returnApi)
};
};