The structure of by database is as follows:
my-db
|
Users
|
CreatedAt: "SOME_VALUE"
|
Email: "SOME_EMAIL"
|
Mailboxes
|
445566
|
Address: "My address 1"
|
Status: Active
|
112233
|
Address: "My address 2"
|
Status: Active
What I am trying to do is to filter only the users who have an active mailbox with a specific id. I am using firebase cloud functions for that purpose and the way I do it is as follows:
db.ref('/Users')
.orderByChild('mailboxes/' + mailboxId + '/status')
.equalTo('Active')
.once("value", function(snapshot){
snapshot.forEach(function(childSnapshot){
// GET SPECIFIC USER DATA FROM childSnapshot
})
})
It seems to be working fine so far, but I am getting a warning error in firebase functions log saying that:
@firebase/database: FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "mailboxes/445566/status" at /Users to your security rules for better performance.
I have tried to add an index in the rules file:
{
"rules": {
".read": true,
".write": true,
"users": {
"$userid": {
"mailboxes": {
"$mailboxid": {
".indexOn": ["status"]
}
}
}
}
}
}
but still no success. I am now wondering what is not correct here.