在Firebase中的其他两个值之间查询值 [英] Query value between two other values in Firebase

查看:51
本文介绍了在Firebase中的其他两个值之间查询值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I have the following structure in 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,因为时间戳不在开始和结束范围之内.

Is it possible to query for example all the images where the current timestamp is between "start" and "end"? So if the current timestamp (which is milliseconds since the Unix epoch) is 1475920987, it would return second_image and third_image but not first_image because the timestamp is not in the Range of start and end.

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

I'm afraid this is not possible because in other stackoverflow questions users pointed out that multiple queries are not possible. So if I want to do a voting system where the user can decide when others are allowed to vote, is it possible to show users only votable images? Even if multiple queries are not allowed?

我正在使用iOS和Android Firebase SDK,但没有特定于语言的答案.

I am using the iOS and Android Firebase SDKs but a language specific answer is not necessary.

推荐答案

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

You can use both queryStarting(atValue:) and queryEnding(atValue:) in a single query.

所以您需要类似的东西:

So you need something like:

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

这篇关于在Firebase中的其他两个值之间查询值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆