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

542
Visualizações
How can update new Field data to existing document without overwrite to existing data in firebase-9 by react native

I try to update data by adding new Field into existing data in firestore by react native expo when I try to update by setDoc() , all existing data removed and only newly update one remian How can update data into same document in firebase here my firestore data

can someone guide me how can add new Field without losing existing data in firestore.

here is my attemp by setDoc

const updateUser = async(key, value) => {
  await addDoc(doc(db,'users',user.uid), { [key]: value })
};

I try to add is new Field . how can add new field I also try as follow

 const updateUser = async(key,value)=>{
    const updateRef = doc(db, "users",value);
    await updateDoc(updateRef, {
      [key]: true
    });
   }

this is new Field I try to add enter image description here

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

0

You need to set option merge.

firebase 9+

function updateData(collPath, data) {
    setDoc(doc(db, collPath, data.id), data, { merge: true})
}

firebase 8-

function updateData(collPath, data) {
    db.collection(collPath).doc(data.id).set(data, { merge: true })
}

And in both of libraries you can use function updateDoc() or v8 ...doc().update()

about 4 years ago · Juan Pablo Isaza Relatório

0

You can import firestore from firebase library

import firestore from '@react-native-firebase/firestore';

And then you can get the document reference you need

const docRef = firestore().collection('Users').doc('ABC')

after that you can update your doc by method update()

  docRef
  .update({
    age: 31,
  })
  .then(() => {
    console.log('User updated!');
  });

Detailed about usage of firestore you can find in this documentation https://rnfirebase.io/firestore/usage

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