Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json Firebase复杂查询子句_Json_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Json Firebase复杂查询子句

Json Firebase复杂查询子句,json,swift,firebase,firebase-realtime-database,Json,Swift,Firebase,Firebase Realtime Database,如果我在Firebase中具有以下结构: { "images": { "first_image": { "url": "https://ima.ge/first_image", "uploader": "john", "timestamp": "1465920841" }, "second_image": { "url": "https://ima.ge/second_image", "uploader":

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

{
  "images": {
    "first_image": {
      "url": "https://ima.ge/first_image",
      "uploader": "john",
      "timestamp": "1465920841"
    },
    "second_image": {
      "url": "https://ima.ge/second_image",
      "uploader": "louis",
      "timestamp": "1465920987"
    },
    "third_image": {
      "url": "https://ima.ge/third_image",
      "uploader": "peter",
      "timestamp": "1465920990"
    }
  },

  "votes": {
    "first_image": {
      "john": "up",
      "louis": "down"
      "francis": "up"
    },
    "second_image": {
      "john": "up",
      "louis": "down"
    },
    "third_image": {
      "francis": "up"
    }
  }
}
例如,是否可以查询所有john未通过Firebase投票的图像

我通读了文档,据我所知,这些类型的查询根本不可能。因此,如果这是不可能的,我如何尝试重新构造我的数据,以便能够像我给出的示例中那样进行查询

我使用的是“新”Firebase控制台,目前是Firebase SDK的iOS和Android版本,但我不需要具体的示例,而是想了解如何在Firebase中进行复杂查询,可以通过重新构造数据,也可以通过正常查询(如果我误解了文档)

在客户端过滤数据的最大问题是,可能会有数百万张图像,检索所有这些图像将非常糟糕……

是的,您可以这样做

下面是一个查找没有john投票的节点的示例,它将从问题中的结构返回第三个_图像节点

let ref = self.myRootRef.childByAppendingPath("votes")
ref.queryOrderedByChild("john").queryEqualToValue(nil)
      .observeEventType(.Value, withBlock: { snapshot in
      for child in snapshot.children {
           print(child)
      }
})
记住。Value返回多个节点,所以我们需要迭代,然后使用for child。。。去了解每一个人


作为旁注,如果这些是Firebase用户,您应该使用userId而不是人名。尽可能解除动态数据(例如人名)与其键的关联,并引用该键。John将来可能想被称为Johnny。

谢谢,实际上我在为用户和图像使用UID。这只是一个简单的例子,不会把任何人与UID混淆。另一个可能相关的问题是:如果我有一个“开始”和一个“结束”值,基本上都是时间戳,怎么可能只得到那些正在“运行”的孩子?因此,当前时间戳在这两个时间戳内。这是否可能,因为我认为多个查询是不可能的。“我能把它组织成这样吗?@Ybrin不,所以我理解这个问题。是否要查找值介于其他两个值之间的节点?不管怎样,这听起来像是一个新问题,所以发布它,让我们看看我们能想出什么。好的,这是一个新问题: