[英]Firebase: Is it reliable to use a shortened version of a document ID?
I want to add a new field in my candidates collection which is called shortCandidateId.我想在我的候选人集合中添加一个名为 shortCandidateId 的新字段。 This ID would be a substring of the first 5 characters from the actual ID of the document, and in lower case.
此 ID 将是来自文档实际 ID 的前 5 个字符的 substring,并且小写。
For example:例如:
Regular Id from Firebase version: 0KdeD344kfed
Shortened version: 0kded
Is it reliable to use this shortened version to get the data from the document?使用这个缩短的版本从文档中获取数据是否可靠?
Are there possible collision when transforming the candidate ID to this shortened version?将候选 ID 转换为此缩短版本时是否可能发生冲突?
97ADsjuTPxOktx5FC1gx = 97aDs
97ADsjuTPxOktx5FC12x = 97aDs
In this case I'd have two candidates with the same ID and I could not fetch the correct one.在这种情况下,我将有两个具有相同 ID 的候选人,但我无法获取正确的候选人。
Any time you put the same amount of information in smaller set of bits, you'll have a chance of collisions.每当您将相同数量的信息放入较小的位集时,您就有可能发生冲突。 If there wasn't, the original naming scheme would be wasteful.
如果没有,原来的命名方案会很浪费。
So the question is not whether there can be collisions, but how common those will be and how you deal with them.所以问题不在于是否会发生冲突,而在于它们有多普遍以及你如何处理它们。 If you don't want to deal with the collisions, I'd recommend to not change the identifier scheme and use the document IDs as Firestore generates them for you.
如果您不想处理冲突,我建议您不要更改标识符方案并使用文档 ID,因为 Firestore 会为您生成它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.