Firestore return document when it gets updated
As we get the whole document when it is created, it would be nice to get it as well when it gets updated.
Example:
Online game where 4 people join together. In document, we have a list of players with their names. These names should be displayed for all players. Last user joins closing the session. To get the rest of the names after update the document with this last player, I need to do an extra read.
Problem:
I am making an entra call for every player, affecting my quota limitation.
Solution:
Return updated document.
-
Francesco Simonazzi commented
The problem is not just about the Quota, it's also critically important to get the document data at the time of writing. One clear example of this would be when incrementing a numeric field, doc.update({ [field]: FieldValue.increment(1) }), everything works fine in the DB, but server side, how do I know what the value was when it's been incremented by my request? by the time I make a get request, somebody else might have increased already such counter. It mostly defeats the purpose of calling FieldValue.increment if I cannot make sure what the value was when I increased it
@Alexander Trakhimenok, sounds more like a workaround than the actual solution. Honestly I don't understand why the REST Api do return the document, while the various SDKs will not. -
Alexander Trakhimenok commented
This is already implemented - https://firebase.google.com/docs/firestore/query-data/listen