Firebase中的独特属性 [英] unique property in Firebase

查看:307
本文介绍了Firebase中的独特属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含类别的IOS应用程序。 Firebase上的存储空间如下所示:

  -root 
- 类别
-key
- 颜色:
- 名称:
- 总和:
- 费用
- 钥匙$ b $ - 存根:
- 类别:
-
-description:
-initiator:
-name:

用户不得添加两个类别。我想让类别名称独一无二。 Firebase中可以做什么?
在此先感谢。

解决方案

无法确保唯一值 Firebase数据库。



但是另一方面,键在其上下文中始终是唯一

您可以利用这种方式来建模您的数据,以保证您想要的财产的唯一性。假设您希望类别名称是唯一的,请将类别存储在其名称下:

   - 类别
- 名称
- color:
- sum:

有了这个结构,具有唯一的类别名称。

如果您必须将类别存储在当前键的下方,但仍要确保唯一的名称。您可以创建一个二级索引,它使用类别名称作为关键字来确保其唯一性。

   - 类别
- 键
颜色
名称
$ sum
$ category
pre>

后面的方法在Kato对使用Firebase Simplelogin强制实施唯一的用户名


I have an IOS app which contains categories. My storage on Firebase looks like this:

-root
   -Categories
      -key
        - color:
        - name:
        - sum:
   -Expenses
      -key
        -amount: 
        -category: 
        -date: 
        -description: 
        -initiator: 
        -name: 

User must not add a category twice. I want to make category name unique. Is it possible to do in Firebase? Thanks in advance.

解决方案

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

这篇关于Firebase中的独特属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆