【发布时间】:2016-10-17 15:17:06
【问题描述】:
这是Firebase - proper way to structure the DB的后续问题
我有以下数据库结构:
"artists" : {
"-KKMkpA22PeoHtBAPyKm" : {
"name" : "Skillet"
}
}
我想查询艺术家参考,看看艺术家是否已经在数据库中,如果艺术家在数据库中,获取艺术家密钥(在上面的例子中,它是 -KKMkpA22PeoHtBAPyKm)。
我试过了:
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")
}
})
但是“snapshot.key”只给了我“艺术家”的父键。
我怎样才能得到我需要的钥匙?
【问题讨论】:
标签: ios swift firebase firebase-realtime-database