ios - 数据存在时,Swift firebase 快照返回 null
问题描述
我试图简单地从我的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)
}
解决方案
改变这个:
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
在查询中添加引号
推荐阅读
- java - Android 自定义列表视图和适配器不起作用
- javascript - 从 Angular 端发送文件后,在 Node.js 端编码大文件时出错
- android - 尝试使用“2018-07-30T12:31:02”格式格式化日期时出现无法解析的日期异常
- javascript - 如何使 JS 模态内容可通过 URL 访问?
- c# - 带有索引器的对象接口
- ios - 单个 NSURLSession 的最大主机限制是多少
- keycloak - “无效代码”(令牌),因为已访问过重置密码链接
- android - Android NDK 错误 - 致命信号 11 (SIGSEGV) Android Studio 3.1.3
- django - Django中的TDD,如何对我的模型进行单元测试?
- python - Numpy Python:如何从列表中获取最频繁的 20 项