This is a follow up question to Firebase - proper way to structure the DB
I have the following DB structure:
"artists" : {
"-KKMkpA22PeoHtBAPyKm" : {
"name" : "Skillet"
}
}
And I want to query the artists ref and see if an artist is already in the DB or not and if the artist IS in the DB, get the artist key (in the above example it would be -KKMkpA22PeoHtBAPyKm).
I tried this:
artistsRef.queryOrderedByChild("name").queryEqualToValue("Skillet").observeEventType(.Value, withBlock: { (snapshot) in
if snapshot.exists() {
print("we have that artist, the id is (snapshot.key)")
} else {
print("we don't have that, add it to the DB now")
}
})
but "snapshot.key" only gives me the parent key which is "artists".
How can I get the key I need?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…