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

306
Visualizações
how to add a new key and value to an existing object in firebase 9 without overwriting previous data

I am trying to add to an object in firestore, the problem is the new object overwrites the previous objects so in my case only one object remains, i put a picture of the db and also the logic that I am using.

      const docRef = doc(db, 'items', _authContext.currentUser.uid);

      await updateDoc(docRef, {
        itemlist: {
          [diffrent key each time]:  arrayUnion({ name: 'item whatever')}],
        },
      }), { merge: true };
    };

enter image description here

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

0

You should use dot notation when updating a nested field. Also updateDoc() doesn't take the options with merge property (it's setDoc() that does). Try refactoring the code as shown below:

const docRef = doc(db, 'items', _authContext.currentUser.uid);
const differentKey = "someKey";

await updateDoc(docRef, {
  [`itemList.${differentKey}`]: arrayUnion({ name: "item whatever" }),
});
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