How to write .indexOn for dynamic keys in firebase?
18,145
I guess you're looking for:
{
".read": true,
".write": true,
"rules": {
"Tasks": {
"$groupid": {
".indexOn": "date"
}
}
}
}
The Firebase documentation is usually a pretty good read. Spending an hour or less in the security guide, will ensure you have a better understanding of this and many other topics.
Author by
Marty.H
Updated on June 13, 2022Comments
-
Marty.H about 2 years
I have data set up like this:
Tasks:{ Group 1:{ pushid1:{ date: 18921949021, title: "Do something" }, pushid2:{ date: 18921949021, title: "Do something else" } }, Group 2:{ pushid3:{ date: 18921949021, title: "Do another thing" } } }
I reference it by date so I only get the tasks made after a certain time.
var now = Date.now(); var taskRef = new Firebase(FB + "/tasks/" + thisGroup); taskRef.orderByChild('date').startAt(now).on("child_added", function(snap){ console.log(snap.val()); });
This all works fine, for each group I get a warning message saying something like this:
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "date" at tasks/Group 1 to your security rules for better performance
How do I add that to my security rules? I can't add one for each group a user makes, is there a wild card entry of some type?