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

281
Vistas
how can i update values to an document,where the document is an array

how can i update values to an document,where the document is an array ?

db.get().collection(collection.CATEGORY_OFFER).insertOne(data).then(async(response)=>{ let product = await db.get().collection(collection.PRODUCT_COLLECTION).find({Category:catName}).toArray() console.log(product) var bulkOp = db.get().collection(collection.PRODUCT_COLLECTION).initializeOrderedBulkOp();

                var count = 0;
                db.get().collection(collection.PRODUCT_COLLECTION).find().forEach(function(doc){
                    console.log("first")
                    console.log(catName)
                    console.log(catOffer)
                    console.log(parseInt(doc.Prize)-parseInt(doc.Prize*catOffer/100))
                    bulkOp.find({Category:catName}).updateOne({
                        $set:{
                            offer:true,
                            oldPrize:parseInt(doc.Prize),
                            value:catOffer,
                            Prize:(parseInt(doc.Prize)-parseInt(doc.Prize*catOffer/100)).toFixed(0) 
                        }
                    })
                    count++;
                    if(count % product.length === 0){
                        console.log("second")
                        console.log(product.length)
                        bulkOp.execute();
                        bulkOp =db.get().collection(collection.PRODUCT_COLLECTION).initializeOrderedBulkOp();
                        console.log("helo world")
                        console.log(bulkOp)

                    }
                })
                if(count > 0 ){
                    console.log("third")
                    bulkOp.execute();
                }
                 console.log("fifth")              
                console.log(bulkOp)
                console.log(product)
               
            })
about 4 years ago · Juan Pablo Isaza
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