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

133
Vistas
Unable to sync new data and update the duplicate one with new data

I get updated and new products which i have to save in my db. The data which i recieve should be like if there is a new SKU it gets added and if there is an SKU whose details are updated then it should be updated. For eg if there is no SKU then it gets deleted in db as well

The for loop which i use below gives me updated products but it donot delete the pervious one for eg i there is and sku name ABC and i rename it to DEF then both the entries remain in my db, i want DEF to replcace ABC

In mappedProducts i get all the products

let updatedProducts = mappedProducts.filter(p => savedSKUs.indexOf(p.sku) != -1);
let newProducts = mappedProducts.filter(p => savedSKUs.indexOf(p.sku) == -1);
await dbProducts.insertMany(newProducts);
               
                for(let i= 0; i< updatedProducts.length; ++i){
                    let currentData = updatedProducts[i];
                    let operatingSKU = currentData.sku;
                    //await dbProducts.findOneAndDelete({sku: currentData.sku});
                    await dbProducts.findOneAndUpdate({
                        SGID: req.decoded.SGID,
                        sku: operatingSKU
                    },{$set: currentData})
                }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

it's your filter that blocks the update because it has both values so it can't find the object to update.
Your filter should only contain the SGID value and the update one the sku value

about 4 years ago · Juan Pablo Isaza 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