gpt4 book ai didi

firebase - 如何编写具有唯一 ID 的 firebase 规则

转载 作者:行者123 更新时间:2023-12-01 11:24:36 25 4
gpt4 key购买 nike

这是我的问题:

WARN: FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "id_logement" at /images/-KNx2y3mAkJZ-Poa7R03 to your security rules for better performance 

我不是真正的 Firebase 和规则大师,所以它对我来说并不真正意味着什么......但我知道有一个问题!

这是我的数据结构:
enter image description here

这是我的规则!

{
"rules": {
".read": "auth != null",
".write": "auth != null",
"accounts" : {
".read": true,
".write": true,
".indexOn": ["userId", "email", "lat",]
},
"geofire" : {
".read": true,
".write": true,
".indexOn": ["g"]
},
"logements" : {
".read": true,
".write": true,
".indexOn": ["id_account"]
}



}
}



我认为这是因为我不知道如何在规则中写这个 Unique id !你能帮我吗?谢谢

最佳答案

回答您的问题,您希望在规则中使用的是 $id 表示法,它是表示分支键的通配符。

{
"rules": {
".read": "auth != null",
".write": "auth != null",
...
"images": {
"$imageId1": {
".indexOn": "id_logement"
}
}
}
}

但是,请记住,您不应将 imagesUrl 存储在两层深的 key 中。使您的代码具有 images/imageUniqueKey/imageData 结构,而不是 images/imageUniqueKey1/imageUniqueKey2/imageData。然后您将拥有如下规则。

"images": {
".indexOn": "id_logement"
}

关于firebase - 如何编写具有唯一 ID 的 firebase 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38677281/

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