ios - Swift firebase 快照在数据存在时返回 null

标签 ios swift firebase firebase-realtime-database

我试图简单地从我的 firebase 数据库中获取所有具有等于我的 postId 的子值的通知。我知道它确实存在,如果我尝试几次它最终会返回快照。这可能是什么问题?

let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: postId).queryEqual(toValue: postId)
        ref.observeSingleEvent(of: .value) { (snapshot) in
            print(snapshot.value)
        }

Database

最佳答案

改变这个:

let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: postId).queryEqual(toValue: postId)

进入这个:

let ref = Database.database().reference().child("notification").child(postUserId).queryOrdered(byChild: "postId").queryEqual(toValue: postId)

在查询中为postId添加引号

关于ios - Swift firebase 快照在数据存在时返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59284030/

相关文章:

javascript - 在对象内搜索 javascript

ios - 如果在释放对象所属的池后释放对象,可能会发生什么?

ios - XCode 只显示信息和build设置而不显示其余部分?

ios - 如何减少 Swift 中的代码冗余?

java - 按用户名在 FirebaseDatabase 中搜索用户

firebase - 使用 firebase/auth 从本地获取当前用户(beta 9)

ios - 在 UIImagePicker 和 UISaveVideoAtPathToSavedPhotosAlbum 之后找到 mediaPath

c# - 如何在 iOS 上访问用户的 MKAnnotationView

ios - 计算一下我在 SpriteKit 中失败的游戏次数?

ios - 快速获取collectionView中心单元格的indexPath?