Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh DocumentSnapshot after setData() without additional query

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())

like image 280
Tiago Santos Avatar asked Mar 24 '26 12:03

Tiago Santos


1 Answers

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.

like image 193
Doug Stevenson Avatar answered Mar 26 '26 01:03

Doug Stevenson