firebase Error Consider adding .indexOn:
*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()
Firebase security rules continue to ask Consider adding .indexOn: even after adding indexOn
Indexes needs to be defined on the location where you use them in your query. So to define an index on /users
with the username
property of each child node:
"users" : {
".indexOn" : "username"
}
Using an unspecified index. Consider adding .indexOn: g
Removing the brackets around ["g"] fixes the problem. Here is the final piece of code:
"rules": {
"karmadots": {
".read": true,
".write": true,
"geofire": {
".indexOn": "g"
}
}
}
FIREBASE WARNING: Using an unspecified index. Consider adding .indexOn: Keyboards at / to your security rules for better performance
You are running the same query multiple times and ordering by the same child each time: Keyboards
. Firebase is telling you that you probably want to index this search, kinda like telling the database that your are going to do this often so be prepared that I am going to do this search often.
It is explained here: Index your data
You can set up indexes under Database -> Rules in your project.
Annoying issue regarding indexOn in Firebase rules
I solved it!
The thing I did not realize was that the above code in my question DOES print the snapshot successfully after adding the appropriate index definition on /users. My issue was realizing you need to loop through the snapshot if you want to further access data of the username snapshot I was querying for accordingly. That would look something like this
let ref = Database.database().reference().child("users").queryOrdered(byChild: "username").queryEqual(toValue: passedInFriendString)
ref.observeSingleEvent(of: .value) { (snapshot) in
for child in snapshot.children {
guard let snap = child as? DataSnapshot else {return}
if snap.hasChild("email") {
print("It has an email")
}
}
}
Thanks to Frank above for guiding me and confirming that I was on the right track. I'm happy to have learned something new and super efficient whenever I need to grab data.
firebase .indexOn warning with autoId
Most likely you are trying to query the comments for a specific post.
In that case you need to tell the database to index the comments for each post. The syntax for that is:
"rules": {
".read": "auth != true",
".write": "auth != true",
"comments" : {
"$commentId": {
".indexOn" : ["count"]
}
}
}
With this you can order the comments for a specific post by the value of their count
property.
Related Topics
How to Synchronize Coredata with Webservices in Swift
Swift Any Difference Between Closures and First-Class Functions
Ambiguous Use of Operator '-' in Swift with 'Abs()'
Implemented Helper App But Does Not Launch on Login
Is Gamescene.Sks Not Recommended for Game Building
Change the Font of a Datepicker
Xcode - Build Setting "Excluded_Source_File_Names" Not Working
Alamofire Not Handling Authentication Challenge
How to Pass a Class and Method to Create an Instance of a Class
JSONserialization.JSONobject Performance in Swift
Integer Literal Overflows When Stored into 'Int'
Integrate Existing Aws Cognito User Pool into iOS Project with Amplify
How to Unwrap Arbitrarily Deeply Nested Optionals in Swift
Delegate Property with Different Type in Swift
Swift Repl: How to Save/Load the Repl State? (A.K.A. Suspend/Resume, Snapshot, Clone)