如何根据Firebase中该子节点的变量观察节点的子项

时间:2017-04-15 17:26:52

标签: ios objective-c swift firebase

我正在创建一个消息传递应用,并使用Firebase作为后端。我知道如何使用observe方法和.childAdded观察给定节点的添加子节点。我的数据结构为

  • 节点
    • ChildNode1
      • 密钥1:数值1
      • 密钥2:VALUE2
      • 密钥3:值3
      • 时间戳的:int
    • ChildNode2 。 。

有没有办法观察父节点但只检索时间戳值大于特定值的子节点?所以我不需要检索所有子节点,只保留那些符合要求的子节点?

先谢谢。

编辑1:这是我用来检索子节点的代码:

let userMessagesRef = FIRDatabase.database().reference().child("DataStructure").child("ListOfItems").child("ParentNode")
observerHandler = userMessagesRef.observe(.childAdded, with: { (snapshot) in
    //My code would go here

    //This works as required AFTER all the data is downloaded
    //In other words, once the previous (not needed) childnodes and those I want are downloaded
    //I can use it for subsequent and newly added childnodes

    //However, I don't want to retrieve all the childnodes everytime this runs
    //I want to only retrieve childnodes that were added after a particular time
    //I save the timestamp as Int of seconds in the childnode.
    //I also save the timestamp of last retrieve childnode in the app
    //What I ideally want is to retrieve all childnodes after the timestamp
    //saved in the app (something like any childnode with timestamp greater than the timestamp int in the code)
}, withCancel: nil)

如果我将观察者添加到查询中,并将查询设置为在我保存的本地时间戳之后检索带有时间戳的子节点,它是否会起作用。

由于

0 个答案:

没有答案