2017-09-22 68 views
0

我在swift中使用firebase从Firebase实时数据库读取一些数据。当我在火力面板有一个项目它的做工精细,但添加另一个项目后,今天我得到了错误这样firebase错误考虑添加“.indexOn”:

2017年9月23日00:15:18.360 AfgDate [2816] [火力地堡/数据库] [我-RDB034028]使用未指定的索引。您的数据将在客户端下载并过滤。考虑加入“.indexOn”:‘日期’,在/数据安全规则获得更好的性能

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

我的角色是

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

,我以后改变了我的角色,这一个

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

在这个时候还我不能读取数据,并和我没有看到任何错误控制台 这是我在迅速

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) 

    }) 

代码数据库的图像如何

回答

1

请研究意见,以了解问题是如何解决的。

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

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

     } 
    } 

并尝试这个

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

,而不是

ref = Database.database().reference() 
+0

我改变我的角色那样,但我仍然不能读也没有错误显示在我的控制台 –

+0

它不工作 –

+0

相同的问题不是亲爱的工作 –

2

显示Data作为资本,但你的.indexOndata不是。你想要你的规则是这样的:

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

我刚才测试了一些规则,发现它们区分大小写。

+0

亲爱仁的人,我这样做,也将其更改为数据,但我不能阅读任何东西也有在控制台中没有错误 –

+0

您也正在尝试从孩子的“数据”中读取数据,而不是“数据”,因此您需要在代码中更改该数据。 –

+0

我改变了那一个也从数据到数据stil我不能读 –