我有以下数据,如图所示。
我想确保用户名字段是唯一的。我怎样才能强制执行呢?请记住,我的文档 ID 已经是唯一的,我不想使用我的用户名作为文档 ID
无法在 Firestore 中强制执行字段的唯一值。您可以保证的唯一唯一性是集合中的文档 ID,因此解决方案是创建一个新集合,其中将用户名用作文档 ID。
这个问题之前已经讨论过几次了,所以我建议检查一下:
- Firestore 安全规则检查角色用户名是否已存在 https://stackoverflow.com/questions/52016426/firestore-security-rule-to-check-if-character-username-already-exists/52017880#52017880
- 检查 Cloud Firestore 中文档字段的特定值 https://stackoverflow.com/questions/49372164/check-a-document-field-for-a-specific-value-in-cloud-firestore/49372447#49372447
-
我想在 firebase/firestore 中创建唯一的用户名 https://stackoverflow.com/questions/67111638/i-want-to-make-unique-usernames-in-firebase-firestore,其中显示了一些相关的安全规则。
- Cloud Firestore:强制执行唯一的用户名 https://stackoverflow.com/questions/47405774/cloud-firestore-enforcing-unique-user-names
-
Firestore唯一索引或唯一约束? https://stackoverflow.com/questions/47543251/firestore-unique-index-or-unique-constraint/59892127#59892127,包含代码和规则示例的更完整的文章。
- Cloud Firestore:强制执行唯一的用户名 https://stackoverflow.com/questions/47405774/cloud-firestore-enforcing-unique-user-names/53032126#53032126
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)