Reputation: 36659
I have a Firebase data structure that looks like:
-messages
-myFirstUsername
-5-2-16 04:02:23 AM
-message: 'messageOne',
-direction: 'outgoing'
-5-3-16 04:07:23 AM
-message: 'messageTwo',
-direction: 'outgoing'
-mySecondUsername
-5-4-16 04:02:23 AM
-message: 'messageOne',
-direction: 'outgoing'
-5-5-16 04:02:23 AM
-message: 'messageTwo',
-direction: 'incoming'
I would like to index all data using the message
and direction
nested child keys. Since the username keys under the messages
object are dynamic, I'll need to set up my index on the messages
object itself.
Will the following rule set up indices two levels deep?
{
"rules": {
"messages": {
".indexOn": ["message", "direction"]
}
}
}
Upvotes: 1
Views: 2808
Reputation: 28750
You can specify dynamic .indexOn like this:
{
"rules" : {
"messages" : {
"$userId": {
".indexOn" : ["message", "direction"]
}
}
}
}
I can't seem to find it in the new docs, but here's the old docs description: https://www.firebase.com/docs/security/api/rule/path.html
Upvotes: 6