I have this database structure:
I am trying to get the node value (for example: -KzjZJvEQRBlRG8m2RxO) if the objectId value is equal to a specific value.
Let me give you an example: if the object id is equal to "-Kzx6b-w3cbE_3e1MwWr" then i would like to get the node value (-Kzx6bVxJHq0HgDjkhH8) so i can delte the record.
I tried to do it like so:
let query = Api.Notification.NOTIFICATION_REF.queryOrdered(byChild: "objectId").queryEqual(toValue: id)
query.observeSingleEvent(of: .value, with: { (snapshot) in
for snap in snapshot.children {
print (snap.key)
}
However i get no value in the print statement Actually is seem not to enter at all the for cycle.
Is there a way to achieve this?
Thank you!
-----UPDATE Would a solution like this affect the speed if i get many records?
Api.Notification.NOTIFICATION_REF.observeSingleEvent(of: .value, with: { (snapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
Api.Notification.NOTIFICATION_REF.child(key).observeSingleEvent(of: .value, with: { (userid) in
for subChild in userid.children {
let subSnap = subChild as! DataSnapshot
let subKey = subSnap.key
//get the value here
}
})
}
})