我正在将实时数据库与Google的Firebase结合使用,并且正在尝试检查是否存在孩子。
我的数据库结构如下
- / (root) - /users/ –- /james/ -- /jake/ - /rooms/ -- /room1/ --- (room 1 properties) -- /room2/ --- (room 2 properties)
我想检查room1是否存在。我尝试了以下方法:
let roomName:String = "room1" roomsDB.child(roomName).observeSingleEventOfType(.Value) { (snap:FIRDataSnapshot) in let roomExists:Bool = snap.value != nil ? "TAKEN" : "NOT TAKEN" }
在访问snap.value它时,返回该房间属性的JSON,但是我如何检查room(/rooms/room1/)是否从那里开始呢?
snap.value
/rooms/room1/
评论是否需要任何澄清
self.ref = FIRDatabase.database().reference() ref.child("rooms").observeSingleEvent(of: .value, with: { (snapshot) in if snapshot.hasChild("room1"){ print("true rooms exist") }else{ print("false room doesn't exist") } })