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

251
Vistas
How to delete a Firestore field inside a map that is an array element?

I would like to be able to delete varToDelete field inside a map if a condition occurs.

For some reason, the code to delete it is reached, but nothing is happening

Here is the structure of my document:

loc [
  {
    var1,
    var2,
    varToDelete
  },
  {
    var1,
    var2,
    varToDelete
  }
]

So, I started to think about this code:

await db.runTransaction(async (t) => {

  var locRef = db.collection('documents').doc('123-456');
  var locSnapshot = await locRef.get();
  var loc = locSnapshot.data().loc;

  loc.forEach(l => {
    if (typeof l.varToDelete !== 'undefined') {
      t.update(locRef, {
        "varToDelete": admin.firestore.FieldValue.delete()
      });
    }
  });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

"varToDelete": admin.firestore.FieldValue.delete()

This will delete a field 'varToDelete' in the document itself. There is not direct method to delete a field from maps in an array. You must read the doc, remove that property from the objects and update the document with the whole new 'loc' array.

const newArr = locSnapshot.data().loc.map(({varToDelete, ...rest}) => rest)
t.update(locRef, {loc: newArr})
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