Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda