Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Mongoose made function avoid duplicating

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

enter image description here

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

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

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;
        }
        ...
      }
  });
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!