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

226
Vistas
MongoDB - Massive array update using array's content pre-update

I had a problem where I have to update a collection which looks like this :

{
  "_id": ObjectId("61d229d13f5f944815deb7ca"),
  "date": "2022-01-02",
  "infos": [
    {
      "expiration": "2022-06-17",
      "rate": 1.0
    },
    {
      "expiration": "2022-06-17"
    }
  ]
}

And I want it to be like this, wihch means in infos array, if there's a rate then create an object rate with type, type2 and the value that was in rate before And if it was null, then the value is null

{
  "_id": ObjectId("61d229d13f5f944815deb7ca"),
  "date": "2022-01-02",
  "infos": [
    {
      "expiration": "2022-06-17",
      "rate": {
        "type": null,
        "type2": null,
        "value": 1.0
      }
    },
    {
      "expiration": "2022-06-17",
       "rate": {
        "type": null,
        "type2": null,
        "value": null
      }
    }
  ]
}

I want to change every object like this, not using javascript since it's a 10 M collections and it's very slow (15H+) using a js script.

Here is the script i've written:

db.derivativeObservedPrice.update(
{"asOfDate": "2022-06-06"},
{$set: {
    "legs.$[].rate": { 
               "type" : null,
               "type2": null,
               "value": null // use rate pre-update value?
           }
   }
},           
{multi : true}
)

But I don't really know how to acces previous rate value.. Is there a way to do this ? I'm pretty sure there is but haven't found the answer yet.

Thanks in advance !

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