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

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

问题描述

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

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: 

用户不得两次添加类别.我想让类别名称唯一.是否可以在 Firebase 中进行?提前致谢.

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

推荐答案

无法确保 Firebase 数据库中的唯一值.

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

但另一方面,键在其上下文中总是唯一的.

您可以利用它来为您的数据建模,以保证您想要的属性的唯一性.假设您希望类别名称是唯一的,请将类别存储在其名称下:

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

在 Kato 对 强制使用唯一用户名的回答中进一步解释了后一种方法使用 Firebase 简单登录

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

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