问题
we've been using realtime database to save some data from mobile devices (ios, android + now web). I earlier asked if the order, in which other clients see the data, is guaranteed to be the same order in which client wrote those. (here Does Firebase guarantee that data set using updateValues or setValue is available in the backend as one atomic unit? , the title is a bit misleading, but the answer is there)
The answer was yes, and now we're migrating to Firestore and I'm wondering if the same applies to Firestore too?
So, If I write in client A documents 1, 2 and 3 is it guaranteed that Client N will observe the writes (given that there is a suitable listener) in the same order as client A wrote those?
Does this apply to Cloud Functions too? We're writing 3 pieces of data to separate documents and then we write fourth document as a way to trigger a function to do some processing. So is it guaranteed that the 3 documents written earlier will be available when the function is triggered?
Note that the 4 documents are NOT written in the same transaction or batch, but as separate document.create calls.
回答1:
It would be catastrophically bad if the order of writes was not maintained within an individual client. The client would not have a strong internal understanding of the state of the system after such a series of writes, and it would have to read every document back in order to validate the contents written.
So you can expect that the order would be maintained. However, if you aren't using a transaction, there are no guarantees about the order of writes to document coming from multiple clients.
来源:https://stackoverflow.com/questions/49646498/firestore-order-of-writes