0

i have the following structure:

Firebase Image

how i can get all parent key where child value contain 4YCpSJIECJaMEp5poIGL4rIFnbs1

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
iboy15
  • 35
  • 1
  • 9
  • Firebase Database queries can only search across level of child nodes. Since your JSON structure contains two unknown levels, you can't query for a value. See https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Aug 14 '19 at 14:19

1 Answers1

2

You can't get only a parent key with Firebase's queries. If you get parent's key you'll retrieve childs too. What you can do is first query on your key filter and then do the rest on front side. Try the following:

firebase.database().ref("roomUsers").orderByValue().equalsTo(key).once("value").then(snap => {
   const keys = [];
   snap.forEach(s => {
      keys.push(s.key);
   });
});
Emeric
  • 6,315
  • 2
  • 41
  • 54