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

214
Visualizações
Modify arrays in Firebase Firestore

The Firestore database has the following field structure

images: {day: ['url1', 'url2', 'url3,] night: ['url1']}

First I would like to be able to append a value to the arrays. Did try the following:

await updateDoc(doc(firestore, FIRSTORE_COLLECTIONS.IMAGES, id), {
        [folder]: {
          [key]: arrayUnion(fileUrl)
        }

It went to the right images: path but unfortunately this just created a new array with one value and removed the ones that where there.

Secondly. If I also like to be able to create a new array in the same path with a key that does not exist can this be done and how could that be solved with this setup any ideas?

dependencies: "firebase": "^9.1.1", "react": "^17.0.2"

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is what solved it:

 await updateDoc(ref, {
        [`${folder}.${key}`]: arrayUnion(fileUrl)
      });

Proper path where the arrayUnion methods is implemented. It also creates a new array if key does not exists, which is nice.

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