I need to delete the media object that has value "-LKJ60LdhSaJOzogSccL". In order to delete it, I have to retrieve its key which was previously generated with childByAutoId function.
How can I query media node by value? I need to query media node in order to get a single child which has a certain value.
This is what I tried and it returns null.
let mediaUID = "-LKJ60LdhSaJOzogSccL"
userUID = Q6Dm3IMLNLgBH3ny3rv2CMYf47p1
let refUsers = Database.database().reference().child(users).child(userUID).child("media")
refUsers.queryEqual(toValue: mediaUID).observeSingleEvent(of: .value, with: { (snapshot) in
print("snapshot.value \(snapshot.value)")
// prints null
return
})
users
Q6Dm3IMLNLgBH3ny3rv2CMYf47p1
email: "dondraper@gmail.com"
fcmToken: "d1I..."
media
-LKJ61KoaUUrEt1JtfoS: "-LKJ60LdhSaJOzogSccL"