How to add values to Firebase Firestore without overwriting?

前端 未结 5 1726
孤独总比滥情好
孤独总比滥情好 2020-12-16 17:56

I have two Activities, I am adding data to Firestore from these two activities individually. But, whenever I add second activity data to Firestore, it is overwriting the fir

5条回答
  •  北海茫月
    2020-12-16 18:32

    If you know that the user document allready exists in firestore then you should use

    firebaseFirestore.collection("Users").document(user_id).update(data)
    

    If you don't know if the document exists then you can use

    firebaseFirestore.collection("Users").document(user_id).set(data, {merge:true})
    

    This performs a deep merge of the data

    Alternatively you can do it by using subcollections

提交回复
热议问题