In order to set new data in a Firestore document, I normally use setData() with merge: true. This works fine and as intended regarding data saving:
await userDoc.reference.setData({
'favourite_color': 'blue',
'favourite_team': 'fcporto',
},merge: true);
My only issue is that DocumentSnapshot (userDoc in this example) doesn't get automatically 'refreshed' after setData is finished, which forces me to do an additional query to the document.
Is there any way to automatically update DocumentSnapshot after setData() ? (same behaviour happens with updateData())
No, DocumentSnapshot objects are immutable - the can't be changed. You will have to make another query, or wait for another realtime update from a listener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With