如何在Firebase中使用通配符?

时间:2017-03-19 22:01:50

标签: ios swift firebase firebase-realtime-database

这是我的Firebase数据库结构:

ft-records
  userX@gmail_com
    2013-01-01 00:00:00 GMT
        addedByUser: "userX@gmail.com"
        notes: "Boooo"
        time: "2013-01-01 00:00:00 GMT"
    2013-01-02 10:00:00 GMT
        addedByUser: "userX@gmail.com"
        notes: "Yeaah"
        time: "2013-01-02 10:00:00 GMT"
  userY@gmail_com
    2013-01-01 03:00:00 GMT
        addedByUser: "userY@gmail.com"
        notes: "Ok"
        time: "2013-01-01 03:00:00 GMT"

我可以像这样为经过身份验证的用户查询此数据,例如用户X @ gmail_com

let userRecords = self.ref.child(self.user.email.replacingOccurrences(of: ".", with: "_", options: .literal, range: nil))

userRecords.queryOrdered(byChild: "time").queryStarting(atValue: startOfDayDateString).queryEnding(atValue:endOfDayDateString).observe(FIRDataEventType.value, with: { snapshot in ... } )

但如果我想查询所有用户在特定日期的所有笔记,我该如何实现?

我需要一个通配符来从root读取所有孩子,然后按每个孩子的时间查询。但我不知道该怎么做。

我可以这样做吗?

let ref = FIRDatabase.database().reference(withPath: "ft-records/*")

1 个答案:

答案 0 :(得分:-1)

您可以使用Firebase数据库查询。

let ref = FIRDatabase.database().reference(withPath: "ft-records")
let query =ref.queryOrdered(byChild: "time").queryStarting(atValue: "2013-01-02 00:00:00 GMT").queryEnding(atValue: "2013-01-02 23:59:59 GMT")

有关详细信息,请参阅Firebase documentation on filtering dataFirebase codelab for iOS