How to add values to Firebase Firestore without overwriting?

前端 未结 5 1727
孤独总比滥情好
孤独总比滥情好 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:16

    As per the documentation, you could use as a second parameter {merge:true}, in my experience the problem usually is in the fact that you are trying to store different data but with the same key.

    Even using {merge: true} will always update the current key with the value you are passing in.

    Merge:true Works only if the key does not exist already. I believe every key in a document must be unique.

    To test it try to pass(keeping {merge: true} as the second parameter) data with a different key, it will merge to existing.

提交回复
热议问题