gpt4 book ai didi

swift - firebase 错误考虑添加 ".indexOn":

转载 作者:行者123 更新时间:2023-11-28 10:50:24 27 4
gpt4 key购买 nike

我在 swift 中使用 firebase 从 firebase 实时数据库中读取一些数据。当我在 firebase 面板中有一个项目时它工作正常,但今天添加另一个项目后我得到了这样的错误

2017-09-23 00:15:18.360 AfgDate[2816] [Firebase/Database][I-RDB034028] Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "date" at /data to your security rules for better performance

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

我的角色是

    {
"rules": {
".read": true,
".write": true,
}
}

之后我把我的角色改成了这个

  {
"rules": {
"data": {
".indexOn": "date",
".read": true,
".write": true
}
}
}

此时我也无法读取数据,而且我在控制台中也没有看到任何错误这是我的 swift 代码

ref = Database.database().reference()
ref.child("data").queryOrdered(byChild: "date").queryEqual(toValue: "1396/06/05").observeSingleEvent(of: .value, with: { (snapShot) in
if let snapDict = snapShot.value as? [String:AnyObject]{

for each in snapDict{
let key = each.key as String
let date = each.value["date"] as!String
let name = each.value["text"] as! String
print(key)
print(name)
self.lblshow.text = name
}
}
}, withCancel: {(Err) in

print(Err.localizedDescription)

})

如何

最佳答案

*请研究评论以了解问题实际上是如何解决的。

试试这个,并像 Jen 建议的那样在规则和查询中使用相同的 Data(大写“D”)。

 {
"rules": {
".read": true,
".write": true,
"Data" : {
".indexOn": "date"
}

}
}

然后试试这个

var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()

代替

ref = Database.database().reference()

关于swift - firebase 错误考虑添加 ".indexOn":,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46372756/

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