unique property in Firebase

与世无争的帅哥 提交于 2019-11-28 14:43:35
Frank van Puffelen

There is no way to ensure unique values in the Firebase Database.

But on the other hand keys are always unique within their context.

You can make use of this to model your data in such a way that it guarantees uniqueness of the property you want. Say you want the category name to be unique, store the categories under their name:

-Categories
  -name
    - color:
    - sum:

With this structure you're guaranteed to have unique category names.

If you must store the categories under their current keys, but still want to ensure unique names. You can create a secondary index, which uses the category names as keys to ensure their uniqueness.

-Categories
  -key
    - color:
    - name:
    - sum:
-CategoryNames
  -name: key

This latter approach is explained further in Kato's answer to Enforcing unique usernames with Firebase simplelogin

souvickcse

You have to check that if the same category is already there or not. Create a search with the specific category values (where clause) if there is already a category with the values don't add it. For how to search a specific result with firebase, you can check this link https://stackoverflow.com/a/14965065/2246798

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!