Reputation: 33
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
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
Upvotes: 2
Views: 5427
Reputation: 2424
*Please, study the comments to know how the problem was actually solved.
Try this, and with the same Data
(with capital "D") 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()
Upvotes: 4
Reputation: 7546
The image of your database shows Data
as capitalized, but your .indexOn
data
isn't. You want your rules to be like this:
{
"rules": {
"Data": {
".indexOn": "date",
".read": true,
".write": true
}
}
}
I tested a couple rules myself just now and found out that they are case sensitive.
Upvotes: 2