I got a problem against all duplicate document on my DB :
I made that code like a filter to compare my joblist to adref: element.redirect_url || title: element.title existing on my DB
const jobList = ["adref":"eyJhbGciOiJIUzI1NiJ9.eyJzIj", "title":"Electrotechnicien H/F", "adref":"eyJhbGciOiJGRfzNiJ9.eyJY5Ij", "title":"Chargé d'études Raccordement H/F", "adref":"eyJHRFRciOiJGRfzNiJ9.eyJ3uIj", "title":"Chargé de Projets H/F"]
const result = Job.findOne({ adref: element.redirect_url && title: element.title })
for (let i = 0; i < jobList.length; i++) {
if (jobList[i].adref == result) {
console.log("adref : " + jobList[i].adref + " already exist on DB");
continue
}
else{
var adref = jobList[i].adref;
var title = jobList[i].title;
var desc = jobList[i].description;
//var site = jobList[i].__CLASS__;
var url = jobList[i].redirect_url;
//var date =
console.log( "Job value insert : " + adref + " " + title + " " + desc + " " + url);
assignDataValue(adref, title, desc, url)
//clearJobList.push(jobList[i].adref, jobList[i].title, jobList[i].description);
continue
}
But i got still a duplicate doncument, i don't know why...
Thanks for the attention
Your jobList should be an array of objects:
const jobList = [
{ adref: 'eyJhbGciOiJIUzI1NiJ9.eyJzIj', title: 'Electrotechnicien H/F' },
{
adref: 'eyJhbGciOiJGRfzNiJ9.eyJY5Ij',
title: "Chargé d'études Raccordement H/F",
},
{ adref: 'eyJHRFRciOiJGRfzNiJ9.eyJ3uIj', title: 'Chargé de Projets H/F' },
];
Also, make sure to adjust your findOne filter and compare the result.adref property with the jobList item's one:
Job.findOne({
adref: element.redirect_url,
title: element.title,
}, (err, result) => {
if (err) {
console.log(err)
return
}
for (let i = 0; i < jobList.length; i++) {
if (jobList[i].adref === result.adref) {
console.log('adref : ' + jobList[i].adref + ' already exist on DB');
continue;
}
...
}
});