In my firebase app I am storing objects in an array structure using the push() method that generates unique ids. These objects have a child property called "scheduledDate" How can I create an indexOn rule in firebase to index this field. under events each user has a node, than a child array of their events. /events/userId/arrayOfEvents
I can use orderByChild() to successfully retrieve the records by event scheduled date, but its warning me about the index.
My rules looks like this:
"events":{
".read" : "auth != null",
".write" : "auth != null",
".indexOn": ["scheduledDate"]
}
My code doing the query looks like this:
this.dbEvents = new Firebase(firebaseEventsUrl);
var q;
q = this.dbEvents.child(userId).orderByChild("scheduledDate").limitToLast(limitToLast);
return $firebaseArray(q);
My data looks like this:
events:{
user1:{
-K2NYCT2_uMwsTSfH58O(push generated):{
description: 'event 1',
scheduledDate: 1446730200000
},
--K2NyNh660I4k8loar-z:{
description: 'event 2',
scheduledDate: 1446730200000
},
},
user2:{
}
}
This should work:
{
"rules": {
"events":{
".read" : "auth != null",
".write" : "auth != null",
"$uid": {
".indexOn": "scheduledDate"
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With