2017-09-22 47 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我不能讀 –