Firebase queryStarting似乎不起作用

时间:2017-03-25 10:58:55

标签: swift firebase firebase-realtime-database

这是我的数据结构:

ft-public-records
   2015-01-01 00:00:00 GMT
        addedByUser: "user@gmail.com"
        rating: 1
        time: "2015-01-01 00:00:00 GMT"
        timestamp: 1490437551.593684

没有queryStartAt,我可以毫无问题地获得对象:

self.publicRef.child("2015-01-01 00:00:00 GMT").queryOrdered(byChild: "rating").observe(FIRDataEventType.value, with: { snapshot in
      print(snapshot)
})

结果:

Snap (2015-01-01 00:00:00 GMT) {
    addedByUser = "user@gmail.com";
    rating = 1;
    time = "2015-01-01 00:00:00 GMT";
    timestamp = "1490437551.593684";
}

但是,当我将queryStarting添加为1时,我会得到null。

self.publicRef.child("2015-01-01 00:00:00 GMT").queryOrdered(byChild: "rating").queryStarting(atValue: 1).observe(FIRDataEventType.value, with: { snapshot in
                print(snapshot)
})

结果:

Snap (2015-01-01 00:00:00 GMT) <null>

我错过了什么?

1 个答案:

答案 0 :(得分:1)

我最后通过向houmie-2013-01-01 00:00:00 UTC

添加另一个孩子2013-01-01 00:00:00 UTC来重组json
{
  "ft-public-records" : {
    "2013-01-01 00:00:00 UTC" : {
      "houmie-2013-01-01 00:00:00 UTC" : {
        "rating" : 1,
        "time" : "2013-01-01 00:00:00 UTC",
        "timestamp" : 1.490550817827253E9,
        "username" : "houmie"
      }
    }
  },
}

现在这对我有用:

self.ref.child("ft-public-records").child("2013-01-01 00:00:00 GMT").queryOrdered(byChild: "rating").queryStarting(atValue: 1).observe(FIRDataEventType.value, with: { snapshot in
    print(snapshot)
})