Haji Essa Sultany Haji Essa Sultany - 23 days ago 9
Swift Question

firebase Error Consider adding ".indexOn":

I am using firebase in swift to read some data from firebase realtime database. When I had one project in firebase panel its work fine, but after adding another project today I got error like this


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


This is my database structure
enter image description here

my role was

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


after that i changed my roles to this one

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


in this time also i cant read data and and i didn't see any error in console
this is my code in 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)

})


how

Answer Source

Try this, and with the same Data in rules as well as in your query like Jen suggested .

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

        }
    }

And try this

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

instead of

ref = Database.database().reference()