Firebase使用规则防止重复的类别 [英] Firebase prevent duplicate categories using rule

查看:144
本文介绍了Firebase使用规则防止重复的类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的类别的数据库结构



我想使用 Firebase规则来防止重复数据

这是我的firebase规则


$ b $

  {
rules:{
.read:auth!= null,
写:auth!= null,


categories:{
$ catid:{

.validate: ()。
}
}
}
}
(newData.child('type')。 code>

当我尝试再次插入 java 时,它将插入 java

如何防止插入重复的分类

解决方案

建议由



还更新了 Firebase规则

b
$ b $ $
$ {
.read:auth!= null,
.write:auth!= null,

categories:{
$ categorie:{
.validate:!data.exists()



$ b code


现在,如果数据已经存在,则不会插入数据。



感谢弗兰克van puffelen


Here is my database structure for categories

I want prevent duplicate data using Firebase rules

here is my firebase rule

 {
    "rules": {
    ".read": "auth != null",
    ".write": "auth != null",


    "categories": {
      "$catid": {

       ".validate": "!root.child(newData.child('type').val()).exists()"
      }
    }
} 
}

When I am trying to insert again java it's inserting duplicate of java

how do I prevent to insert duplicate category

解决方案

As per suggested by Frank van Puffelen

I have changed my data structure as following

and also updated Firebase rules as following

{
 "rules": {
   ".read": "auth != null",
   ".write": "auth != null",

 "categories": {
   "$categorie":{
        ".validate": "!data.exists()"
   }
 }
}
}

Now it's not inserting data if data is already there.

Thanks Frank van Puffelen

这篇关于Firebase使用规则防止重复的类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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