I have this Firebase Realtime Database:
{
"groupUsers" : {
"group1key" : {
"user1key" : &quo
There is no way to pre-create the indexes for such a structure. I've covered this type of structure in my answer here and here and the new Firestore documentation (which works similarly in this aspect) even has a documentation page about it.
The recommendation is to store data in a way that allows this lookup in the other direction too. With your current structure you can efficiently look up the users in a group. To also allow looking up the groups for a user, add this structure:
{
"usersGroups" : {
"user1key" : {
"group1key" : "admin",
"group2key" : "admin"
},
"user2key" : {
"group2key" : "readonly",
},
"user3key" : {
"group2key" : "readwrite"
}
}
}