Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda