swift - 如何在 Swift 中自动生成的键上查询OrderedByValue?
问题描述
我需要queryOrderedByValue()
在其密钥是自动生成的节点上。我的数据库的结构如下图所示(/users-pings/$uid/$uid/"auto-id")。
我可以对下面的查询进行哪些更改以实现此目的?
REF_USERS_PINGS.child(currentUid).child(forId).queryOrderedByValue().queryEqual(toValue: "true").observeSingleEvent(of: .value) { (snapshot) in
if snapshot.exists(){
handler(true)
} else {
handler(false)
}
解决方案
Firebase 数据库查询在您运行它们的位置下的每个子节点上运行,因此user-pings
在您的情况下它们会自动跳过第三级。
您只需要指定要订购/过滤的属性,这似乎就在active
这里。所以像:
REF_USERS_PINGS.child(currentUid).child(forId).queryOrdered(byChild: "active").queryEqual(toValue: "true").observeSingleEvent(of: .value) { (snapshot) in
推荐阅读
- ios - 如何在 TableCell 类中使用 navigationController.pushViewController?
- node.js - 模板字符串中不允许使用八进制转义序列
- c - 为什么我在终端中输入的值与我已经存储在数组中的值不匹配?
- java - 与 Redis 数据库共享 Spring Session
- c# - 无法将单元测试添加到 .NET Core 单元测试项目 VS2017
- python - 插值 Python
- php - 如何将徽标附加到 pdf 文件并发送到邮件
- biztalk - BizTalk 管道组件扩展实用程序包:Zip 管道组件
- r - 使用 tidyverse 转换数据(一列)
- javascript - 在 Vegas 滑块中添加上一个/下一个按钮