-1

I have the following Firebase hierarchy.

1

How can I write a query which finds the child where the value is 1 AND I don't know that it is under the node V9T3cEgEGPRmIkMQb32hxa5gG7L2? In this case, I want to find and print out -KeYbk3K1xXlyzOGVVPx (this uid key is generated by Firebase). The main node is eventUser.

aircraft
  • 25,146
  • 28
  • 91
  • 166
szend
  • 83
  • 8
  • You can only get an eventOrganized with values of 1 if you specify the specific eventUser node. Or, you can get all eventUsers which have an eventOrganized with a value of one. What you want is impossible. If you want all eventOrganizeds with a value of 1 over your entire database you'll have to manually loop through it in your code. –  Mar 07 '17 at 09:08
  • By the way, this is a repost of http://stackoverflow.com/questions/42609735/firebase-queryequal-doesnt-work –  Mar 07 '17 at 09:08
  • (1) not quite the same question, because here I'm trying to raise a generic question about Firebase quering and the prevous one was too specific and confusing with the codes (2) you mentioned "you can get all eventUsers which have an eventOrganized with a value of one" how does it look like? with the answer of the prevoius thread I didn't get those records – szend Mar 07 '17 at 09:32
  • I ment to say you can get all eventUsers which have a specific eventOrganized with a value of one. But I already gave you that query and you said it didn't work (even though it should). I think you'd be better of finding a way to restructure your database. –  Mar 07 '17 at 09:48
  • This looks similar to what I described in my answer on categorization: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value. As Pieter says, that would require a different data model to do efficiently. – Frank van Puffelen Mar 07 '17 at 15:10
  • I was thinking about it as well, but what is your idea regarding restructuring? V9T3cEgEGPRmIkMQb32hxa5gG7L2 is the userid given by FB and -KeYbk3K1xXlyzOGVVPx is the eventid given by FB. With current stucture I want to store the Event ids under the User id, where the User attended with Status = 1 – szend Mar 07 '17 at 15:32

1 Answers1

0

Pass the node value in nodeVal

var userId = firebase.auth().currentUser.uid;
return firebase.database().ref('/eventUser/' + nodeVal).once('value').then(function(q) {
   var eventItem = q.val().eventitem;
   console.log(eventitem);  
});
rselvaganesh
  • 1,032
  • 2
  • 18
  • 30