swift - Firebase 中其他两个值之间的查询值

标签 swift firebase firebase-realtime-database

如果我在 Firebase 中有以下结构:

{
  "images": {
    "first_image": {
      "url": "https://ima.ge/first_image",
      "uploader": "john",
      "start": "1465920841",
      "end": "1466920841"
    },
    "second_image": {
      "url": "https://ima.ge/second_image",
      "uploader": "louis",
      "start": "1465920987",
      "end": "1476920987"
    },
    "third_image": {
      "url": "https://ima.ge/third_image",
      "uploader": "peter",
      "start": "1465920990",
      "end": "1484920990"
    }
  }
}

是否可以查询当前时间戳在“开始”和“结束”之间的所有图像?因此,如果当前时间戳(自 Unix 纪元以来的毫秒数)是 1475920987,它将返回 second_imagethird_image 而不是 first_image 因为时间戳不在开始和结束的范围内。

恐怕这是不可能的,因为在其他 stackoverflow 问题中,用户指出多个查询是不可能的。因此,如果我想做一个投票系统,用户可以决定何时允许其他人投票,是否可以只向用户显示可投票的图像?即使不允许多次查询?

我正在使用 iOS 和 Android Firebase SDK,但不需要特定语言的答案。

最佳答案

您可以在单个查询中同时使用 queryStarting(atValue:)queryEnding(atValue:)

所以你需要这样的东西:

let query = Database.database().reference().child("images")
    .queryStarting(atValue:<startTimestamp>)
    .queryEnding(atValue:<endTimestamp>)

关于swift - Firebase 中其他两个值之间的查询值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37867091/

相关文章:

ios - 将 Firebase 数据合并到 TableView 中

swift - 不能用存储的属性覆盖

swift - 使用未声明的类型 'KDDragAndDropManager' 和 'KDDragAndDropCollectionViewDataSource'

swift - 带有 UITapGestureRecognizer 的 UIView 通过拖动传递到它下面的 UITableView?

ios - 单击切换按钮展开/折叠 UITableViewCell 高度

android - 将 FireBase 分析添加到 Eclipse 项目

Firebase:如何在Google Auth方法之后获取用户电子邮件地址

javascript - Firebase 数据库以编程方式检查下载的数据大小

java - 如何返回 DocumentSnapShot 作为方法的结果?

javascript - 从 Firebase 读取完成后返回数组