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

108
Vistas
2D array Firestore using ArrayUnion

I'm trying to create a 2D array in firestore, which can be updated using array union, but am struggling to work out how to do this. I can do it in a 1D array easily with this:

db.collection('subjects').doc('exampleDoc').update({ units: firestore.FieldValue.arrayUnion({ "name": "Example Unit", "id": "123456787654323456765" }) });

Which produced something like this:

name: 'Example Subject',
units: [
    {
        id: '123456787654323456765',
        name: 'Example Unit'
    }
]

But how can I do this with a 2D array with the data below as an example document?

name: 'Example Subject',
units: [
    {
        id: '123456787654323456765',
        name: 'Example Unit',
        subunits: [
            {
                id: '234568765434567',
                name: 'Example Subunit'
            }
        ]
    }
]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You won't be able to do this with a simple arrayUnion. That's because Firestore does not support syntax to locate a specific indexed array element like it can with named, nested fields.

What you'll have to do is read the document, modify the field in memory to make it look the way you want, then update that entire field back to the document.

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