英文:
Does firestore auto generated id depend on path?
问题
有没有可能 id1
和 id2
重复?
英文:
Could a unique ID be a duplicate if I generate an ID from a different path? like:
const id1 = firestore.collection("chat").doc().id;
const id2 = firestore.collection("profile").doc().id;
Is there any chance id1
and id2
could duplicate?
答案1
得分: 2
Is there any chance id1 and id2 could duplicate?
在Firestore的情况下,ID的碰撞是极不可能的,你可以/应该认为它们将是完全唯一的。这就是它们被设计出来的原因。所以你不必担心。
请记住,Firestore中用于生成唯一ID的内置生成器,当你调用CollectionReference#add()方法或CollectionReference#document()方法而不传递任何参数时,会生成随机且高度不可预测的ID,这可以防止在后端基础设施中命中某些热点。
如果你对文档ID的生成方式有兴趣,请查看以下帖子中@FrankvanPuffelen的回答:
Does a unique ID could duplicate if I generate an ID from a different path?
不会。每次你调用
.doc().id
,都会生成一个新的随机文档ID。
英文:
> Is there any chance id1 and id2 could duplicate?
The collision of IDs in the case of Firestore is incredibly unlikely and you can/should consider they'll be completely unique. That's what they were designed for. So you don't have to worry about it.
Keep in mind that, the built-in generator for unique IDs which is used in Firestore when you call the CollectionReference#add() method or CollectionReference#document() method without passing any arguments, generates random and highly unpredictable ids, which prevents hitting certain hotspots in the backend infrastructure.
If you're interested in how exactly the document IDs are generated, please check @FrankvanPuffelen's answer from the following post:
> Does a unique ID could duplicate if I generate an ID from a different path?
No. Each time you call .doc().id
, a new random document ID is generated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论