If you want to update a dynamic property of an object using Firestore without overlapping the current data, set {merge: true}
:
javascriptconst today = '20210323'; const visitorId = ~~(1000 * Math.random()); const db = firebase.firestore(); db.collection('analytics').doc(today).set({ [visitorId]: { visited: true } }, {merge: true});
If you don't include {merge: true}
, you'll overlap the current data.
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.