Firebase queryEqual doesn't work

后端 未结 1 538
萌比男神i
萌比男神i 2021-01-28 23:30

I have the following hierarchy in my Firebase:

\"firebase

func invitedEvents() {
               


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 23:56

    Right,

    DataService.ds.REF_USERS.child("eventItem").child("eventOrganized").queryOrdered(byChild: snap.key).queryEqual(toValue: 1).observe(.value, with: { (snapshot) in ("With Snapshot Key:\(snapshot.value)")})
    

    That doesn't work because you're missing a reference to the V9T3cEgEGPRmlkMQb32hxa5gG7L2 node.

    If you want all the eventOrganized nodes with a value of 1 under that key then you need to use the following query.

    DataService.ds.REF_USERS.child("V9T3cEgEGPRmIkMQb32hxa5gG7L2").child("eventItem").child("eventOrganized").queryOrderedByValue().queryEqual(toValue: 1).observe(.value, with: { (snapshot) in
            print("Snapshot Value:\(snapshot.value)")
    })
    

    Obviously you don't want to reference V9T3cEgEGPRmlkMQb32hxa5gG7L2 directly, you should store this key in a variable for reusability's sake (maybe you have, I can't tell in your code). I think that's what you wanted.

    0 讨论(0)
提交回复
热议问题