gpt4 book ai didi

android - Firebase 规则 setValue 只有当 child 存在时

转载 作者:搜寻专家 更新时间:2023-11-01 08:18:20 25 4
gpt4 key购买 nike

我正在尝试使用规则,但它不起作用。

结构如下:

enter image description here

我有这个命令:DeleteItemFromListRef.child("List").child(obj.getsEventID()).child(ID).child("check").setValue(false);

但我只想在子项(键)存在时将值设置为“false”,这样如果项目被删除,我就不会简单地拥有它:

enter image description here

这是我的规则:

 "List": {
"$listID" : {
"$key": {
"check" : {
".write":"data.child('List').child($listID).child($key).child('key').exists()"
}
}
}

但是,如果子键为空,它仍然会像这样上传数据:

enter image description here

如果有人能帮忙,那就太好了

编辑 2:这里有更简单的规则

"rules": {






"List": {
"$listID" : {
"$key": {
"check" : {
".read":"auth.uid != null",
".write":"auth.uid != null",
".validate":"data.parent().child('key').exists()"

}
}}}}}

+评论:

因此,如果我添加一个新项目,我总是使用 map 更新该项目,但如果我只更改子项 "check",我会使用 "setValue" 方法并希望仅当项目已经存在时才完成 setValue (== child key already exist)

最佳答案

嗯,你也可以先检查 child 是否存在,如果存在则执行上面的命令。

关于android - Firebase 规则 setValue 只有当 child 存在时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55431756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com