0

I have the follow data structure in Firebase Realtime Database.

{
   groups: {
      $groupid: {
        $userid: Boolean
      }
   }
}

Here #groupid and $userid vary.
When a user with id "user0" is in the group "group0", it will be

{
   groups: {
    ...
    group0: {
       user0: true
    }
    ...
   }
}

When the user is removed, it will be user0: false. When I query groups with a specific user, Firebase SDK shows a warning: FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "user0" at /groups to your security rules for better performance

As the user id varies, I think all user ids should be indexed on.
How can I write a relevant security rule?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 2
    There is no way to define a wildcard index. Wanting to do so typically means that you've inverted your data structure. Yours looks similar to the categorization problem I answered here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jun 27 '17 at 13:27

1 Answers1

0

If you want to query groups with a specific user, it is better to make a user maintain group list.

{
    user-groups: {
        user0: {
            group0: true,
            group1: true
        }
    }
}

So, a group has its members and a user has groups he/she belongs to.

grayger
  • 931
  • 8
  • 19