Firestore ID在整个数据库中是否唯一 [英] Are Firestore ids unique across the whole db

查看:29
本文介绍了Firestore ID在整个数据库中是否唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是-如果我们从所有集合和子集合等中收集所有(自动生成的)id,它们是否都唯一?

What i mean- if we collect all the ids(auto-generated) from the all collections and sub-collections and etc. Will all of them unique?

是为了什么?我正在建立一个新功能,用户可以在其中共享子集合中的项目,所以我不确定-我可以在用户子集合之间使用相同的ID.

What for? I'am building a new feature, where users can share their items from sub-collections, so I am not sure - can I use same id between users sub-collections.

谢谢!

推荐答案

Firestore文档ID在同一集合中必须唯一.它们可以在其他集合或子集合中重复.您可以通过手动创建文档来自己进行测试,然后确定它可以正常工作.

Firestore document IDs must be unique within the same collection. They can be duplicated in other collections or subcollections. You can test this for yourself by manually creating the documents and see that it works OK.

实际上,所有自动生成的文档ID都是唯一的,因为它们是随机的,而且两个对象相撞的可能性在天文学上很小.客户端SDK生成具有20个字符的ID,每个ID允许所有小写字母,所有大写字母和所有数字.因此,总共(26 + 26 + 10)^ 20 = 7.0e35个可能的唯一ID的可能组合.(这是一个非常大的数字-后面有35个零的7.)

Practically speaking, all automatically generated document IDs will be unique, because they are random, and there is an astronomically low chance of two of them colliding. The client SDK generates ID with 20 characters, each allowing for all lowercase letters, all uppercase letters, and all digits. So there are a total of (26+26+10)^20 = 7.0e35 possible combinations of possible unique IDs. (That's a very large number - 7 with 35 zeroes after it.)

这篇关于Firestore ID在整个数据库中是否唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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