Firestore ServerTimestamp查询 [英] Firestore ServerTimestamp Query

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

问题描述

我想知道,考虑到多个客户端将写入该集合,对于给定集合中的2个或更多文档,Firestore ServerTimestamp是否有可能完全相同.我之所以这样问是因为,Firestore不会为创建的文档提供自动递增的序列号,因此我们必须依靠ServerTimestamp进行串行写入.我的用例要求对文档进行编号或至少具有类似于线性写入"的外观.模型.我的应用是移动和基于Web的

I am wondering if there is a possibility of the Firestore ServerTimestamp to be exactly the same for 2 or more documents in a given collection, considering that multiple clients will be writing to the collection. I am asking this because, Firestore does not provide an auto-incrementing sequential number to documents created and we have to rely on the ServerTimestamp to assume serial writes. My use-case requires that the documents are numbered or at least have a semblance to a "linear write" model. My app is mobile and web based

(我还有其他方法可以使用递增编号,例如使用 FieldValue.Increment()方法的Firebase Cloud Function,但这会增加一个层次的复杂性和延迟)

(There are other ways to have an incremental number, such as a Firebase Cloud Function using the FieldValue.Increment() method, which I am already doing, but this adds one more level of complexity and latency)

可以安全地假设在给定集合中创建的每个文档都将具有唯一的时间戳,并且不会发生冲突吗?Firestore是将收集的写入排队吗?还是并行执行这些写入?

Is it safe to assume that every document created in a given collection will have a unique timestamp and there would be no collision? Does Firestore queue up the writes for a collection or are the writes executed in parallel?

谢谢.

推荐答案

可以安全地假设在给定集合中创建的每个文档都将具有唯一的时间戳并且不会发生冲突吗?

Is it safe to assume that every document created in a given collection will have a unique timestamp and there would be no collision?

不,假设这样做是不安全的.但是根据写入实际发生的方式,发生冲突的可能性也极小.如果需要有保证的顺序,请在另一个字段中向文档中添加另一条随机数据,并使用其排序顺序以确定性的方式打破任何联系.您必须自己决定这是否适合您的用例.

No, it's not safe to assume that. But it's also extremely unlikely that there will be a collision, depending on how the writes actually occur. If you need a guaranteed order, add another random piece of data to the document in another field, and use its sort order to break any ties in a deterministic fashion. You will have to decide for yourself if this is worthwhile for your use case.

Firestore是将集合的写入排队吗?还是并行执行写入?

Does Firestore queue up the writes for a collection or are the writes executed in parallel?

您应该考虑所有写入都是并行的.无法保证写入顺序,因为这根本无法很好地扩展.

You should consider all writes to be in parallel. No guarantees are made about the order of writes, as that does not scale well at all.

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

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