Firestore写入顺序 [英] Firestore order of writes

查看:43
本文介绍了Firestore写入顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用实时数据库来保存来自移动设备(iOS,Android +现在的Web)的一些数据.我早些时候问过,是否保证其他客户端看到数据的顺序与客户端写入数据的顺序相同. (此处 Firebase是否保证数据集在后端可以使用updateValues或setValue作为一个原子单位吗?,标题有点误导,但是答案就在那里)

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)

答案是肯定的,现在我们正在迁移到Firestore,我想知道是否同样适用于Firestore?

The answer was yes, and now we're migrating to Firestore and I'm wondering if the same applies to Firestore too?

因此,如果我在客户A中写文档1、2和3,是否可以保证客户N将按照与客户A书写顺序相同的顺序观察写操作(假设有合适的侦听器)?

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?

这是否也适用于Cloud Functions?我们将3个数据段写入单独的文档中,然后编写第四个文档,作为触发函数进行某些处理的一种方式.那么是否可以保证触发该功能时可以使用前面编写的3个文档?

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?

请注意,这4个文档不是在同一事务或批中编写的,而是作为单独的document.create调用编写的.

Note that the 4 documents are NOT written in the same transaction or batch, but as separate document.create calls.

推荐答案

如果未在单个客户端中维护写入顺序,那将是灾难性的糟糕.在进行了这样的一系列写操作之后,客户对系统的状态就不会有很强的内部了解,并且它必须读回每个文档才能验证所写的内容.

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.

这篇关于Firestore写入顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆