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

309
Vistas
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 Respuestas
Responde la pregunta

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 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