I want to return an array of parent keys that contain the given child key.
Here is my database (member user IDs with the IDs of every group they are in):
.
For example:
- If I provide
-Lu3Zs4FCW6F4IcMSU8K
it should return the two parent keys,SnGXDFilErWEqFxPgWY5bIIAnPA3
andt1S9N9owgKRGqBaNxs02rru8GpD3
. - If I provide
-Lu3gCYh5QUplnwLdOFA
it should only returnt1S9N9owgKRGqBaNxs02rru8GpD3
The child values (0 or 1) are not known.
Here is what I tried so far:
var members = [];
return await firebase.database().ref('members').orderByChild(groupId).once('value', snap => {
snap.forEach(data => {
members.push(data.key);
});
}).then(() => {
return members;
});
But this code returns both member keys no matter what child key I provide. Any help would be appreciated.