我有一个包含类别的 IOS 应用程序。我在 Firebase 上的存储如下所示:
-root
-Categories
-key
- color:
- name:
- sum:
-Expenses
-key
-amount:
-category:
-date:
-description:
-initiator:
-name:
用户不得两次添加类别。我想让类别名称独一无二。在 Firebase 中可以做到吗?
提前致谢。
没有办法保证独特的价值观在 Firebase 数据库中。
但另一方面键总是唯一的在他们的背景下。
您可以利用它来建模您的数据,以保证您想要的属性的唯一性。假设您希望类别名称是唯一的,请将类别存储在其名称下:
-Categories
-name
- color:
- sum:
通过这种结构,您可以保证拥有唯一的类别名称。
如果您必须将类别存储在其当前键下,但仍希望确保名称唯一。您可以创建二级索引,该索引使用类别名称作为键来确保其唯一性。
-Categories
-key
- color:
- name:
- sum:
-CategoryNames
-name: key
加藤的回答进一步解释了后一种方法使用 Firebase simplelogin 强制执行唯一用户名 https://stackoverflow.com/questions/29970681/enforcing-unique-usernames-with-firebase-simplelogin/29983839#29983839
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)