简体   繁体   English

Firebase:使用缩短版本的文档 ID 是否可靠?

[英]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.

相关问题 获取当前文档的 ID Flutter / Firebase - Get ID of current document Flutter / Firebase 如何获取 firebase Firestore 文档 ID - How to get the firebase firestore document id Flutter firebase,使用一个文档中的引用调用另一个文档 - Flutter firebase, use a reference in a document to call another document 通过文档 ID 获取单个数据 Reactjs Firebase Web ZF20E3C5E54C3AB3D375D66B6 - Fetch Single Data by Document Id Reactjs Firebase Web SDK 9 如何将 user.uid 作为 id 的文档添加到 Firebase 中的集合中? - How to add a document with user.uid as id to a collection in Firebase? 如何按日期对 Firestore 文档 ID 进行排序 firebase flutter - How to sort firestore document id date wise firebase flutter 尝试使用 CODABLE 类通过 id 在 firebase 中查找文档时出现 Swift 错误 - Swift error trying to find document in firebase by id using CODABLE class Firestore - 获取路径未知的 ID 文档 - Firebase Cloud Functions - Firestore - Get document with ID whose path is unknown - Firebase Cloud Functions 在 firebase 存储中一次上传多张照片并将它们的 URL 存储在 firestore 文档中(firebase 版本 9) - Uploading multiple photos at once in firebase storage and storing their URLs in a firestore document (firebase version 9) Firebase 云存储安全规则中Firestore文档参考如何使用? - How to use Firestore Document Reference in Firebase Cloud Storage Security Rules?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM