【问题标题】:How to enforce Uniqueness in a Property of a document field in Google Cloud Firestore如何在 Google Cloud Firestore 中的文档字段的属性中强制执行唯一性 【发布时间】:2021-06-21 19:37:25 【问题描述】: 我有以下数据,如图所示。 我想确保用户名字段是唯一的。我该如何执行?请记住,我的文档 ID 已经是唯一的,我不想使用我的用户名作为文档 ID 【问题讨论】: 标签: firebase google-cloud-firestore unique 【解决方案1】: 无法在 Firestore 中强制执行字段的唯一值。您可以保证的唯一唯一性是集合中的文档 ID,因此解决方案是创建一个新集合,其中用户名用作文档 ID。 这已经讨论过几次了,所以我建议检查一下: Firestore security rule to check if character username already exists Check a document field for a specific value in Cloud Firestore I want to make unique usernames in firebase/firestore,其中显示了一些相关的安全规则。 Cloud Firestore: Enforcing Unique User Names Firestore unique index or unique constraint?,更完整的代码和规则示例。 Cloud Firestore: Enforcing Unique User Names 【讨论】: