Firebase queryEqual ne fonctionne pas

J'ai la hiérarchie suivante dans ma Firebase:

hiérarchie firebase

func invitedEvents() { DataService.ds.REF_EVENTS.queryOrdered(byChild: "eventParticipant").observe(.childAdded, with: { (snap) in print("KEEEY:\(snap.key)") let value = snap.value as? NSDictionary if snap.exists() , value?["eventParticipant"] != nil{ print("eventParticipant:\(value?["eventParticipant"])") var valueArray = value?["eventParticipant"] as! [[Ssortingng:AnyObject]] for (index, element) in valueArray.enumerated() { print("valueArray\(index): \(element)") //self.selectedContacts.append(element as! Participant) if element["partPhone"] as! Ssortingng == "00 11 111 1111" { print("KEY:\(snap.key) PHONE:\(element["partPhone"])") self.eventKey = snap.key print("snap.key:\(snap.key)") //child("eventItem").child("eventOrganized").queryOrdered(byChild: snap.key).queryEqual(toValue: "1") DataService.ds.REF_USERS.child("eventItem").child("eventOrganized").child(snap.key).observe(.value, with: { (snapshot) in print("With Snapshot Key: \(snapshot)") }) //DataService.ds.REF_USERS.queryOrdered(byChild: "provider").queryEqual(toValue: "email").observe(.value, with: { (snapshot) in // print("With Provider:\(snapshot.value)") //}) DataService.ds.REF_EVENTS.child(self.eventKey).observe(.value, with: { (snap) in print(snap) if snap.value is NSNull { print("Event is not found!") } else { let value = snap.value as? NSDictionary print(value?["eventLocation"] , value?["eventCurrency"], value?["eventDesc"], value?["eventBeginDate"], value?["eventEndDate"], value?["eventCurrency"], value?["eventLocation"], value?["eventName"], value?["eventDesc"], value?["eventPrice"]) if let eventAddress = value?["eventLocation"] , let eventCurrency = value?["eventCurrency"], let eventDesc = value?["eventDesc"], let eventBeginDate = value?["eventBeginDate"], let eventEndDate = value?["eventEndDate"], let eventImg = value?["eventCurrency"], let eventLocation = value?["eventLocation"], let eventName2 = value?["eventName"], let eventNote = value?["eventDesc"], let eventPrice = value?["eventPrice"] { let eventDetails = Event( eventAddress: value?["eventLocation"] as! Ssortingng, eventCurrency: value?["eventCurrency"] as! Ssortingng, eventDesc: value?["eventDesc"] as! Ssortingng, eventBeginDate: value?["eventBeginDate"] as! Ssortingng, eventEndDate: value?["eventEndDate"] as! Ssortingng, eventImg: value?["eventCurrency"] as! Ssortingng, eventLikes: 1, eventLocation: value?["eventLocation"] as! Ssortingng, eventName: value?["eventName"] as! Ssortingng, eventNote: value?["eventDesc"] as! Ssortingng, eventPrice: value?["eventPrice"] as! Ssortingng, eventCreated: value?["eventCreated"] as! Ssortingng, eventStatus: 0 as! Int? ) //print(eventDetails) let eventName = value?["eventName"] as! Ssortingng self.userPastEventNameList.append(eventName) self.events.append(eventDetails) print(eventAddress,eventCurrency,eventDesc, eventBeginDate, eventEndDate, eventImg, eventLocation, eventName2, eventNote, eventPrice) } else { print("NULL FOUND") } } DispatchQueue.main.async{ self.tableView.reloadData() } self.removeLoadingScreen() }) //}) } } } }) } 

et snap.keys sont en cours d'printing ("snap.key: (snap.key)"):

 snap.key:-KePXAuTADuTLTsZ7qbe snap.key:-KePjqMKrARQmp-gTss- snap.key:-KePsCS5rB4lTwy6GWea snap.key:-KePwdRQPFFX30_GDAOK snap.key:-KePyNVghX4MkSxI_1fx snap.key:-KePz200QsJp6CSb3bVN 

Si je l'utilise, alors je reçois un instantané:

 print("snap.key:\(snap.key)") DataService.ds.REF_USERS.queryOrdered(byChild: "provider").queryEqual(toValue: "email").observe(.value, with: { (snapshot) in print("With Provider:\(snapshot.value)")}) 

Résultat:

 With Provider:Optional({ JIbrGLdfCDUpMUOHEu7KzRye8ZK2 = { provider = email; }; }) 

Si j'utilise ceci, je n'obtiens aucun résultat:

  print("snap.key:\(snap.key)") 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)")}) 

Résultat:

 With Snapshot Key:Optional(<null>) 

Quelqu'un pourrait m'aider? Qu'est-ce que je fais mal?

Droite,

 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)")}) 

Cela ne fonctionne pas car il vous manque une reference au nœud V9T3cEgEGPRmlkMQb32hxa5gG7L2.

Si vous voulez que tous les noeuds eventOrganized dont la valeur est 1 sous cette key, vous devez utiliser la requête suivante.

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

Évidemment, vous ne voulez pas referencer V9T3cEgEGPRmlkMQb32hxa5gG7L2 directement, vous devriez stocker cette key dans une variable pour l'amour de la réutilisabilité (peut-être que vous avez, je ne peux pas dire dans votre code). Je pense que c'est ce que tu voulais.