【问题标题】:Retrieve only childAdded from firebase to my listener in firebase仅检索从火力库添加到火力库中的我的侦听器的子项
【发布时间】:2018-11-14 15:33:54
【问题描述】:

我目前正在运行这个 python 脚本

# Setup Firebase Listner

# Retrieve the data from Firebase and do the analysis

# Append the data to Firebase

from firebase_streaming import Firebase

# Firebase object
fb = Firebase('https:***************.firebaseio.com/')


# Callback function to Analyze the data for a Faulty Motor
def performAnalysis_FaultyMotor(x):
    print(x)

def performAnalysis_motor(x):
    print(x)

# Declaring Custom callback definitions for the faulty and motor data
custom_callback_faultyMotor = fb.child("accelerometerData/faultyMotorData").listener(performAnalysis_FaultyMotor)
custom_callback_motor = fb.child("accelerometerData/motorData").listener(performAnalysis_motor)


# Start and stop the stream using the following
custom_callback_faultyMotor.start()
custom_callback_motor.start()

这将返回我连接了我的侦听器的相应节点下的全部数据。

但我只需要该节点下新添加的子节点。

知道我怎么能做到这一点???

【问题讨论】:

    标签: python firebase firebase-realtime-database


    【解决方案1】:

    Firebase 同步数据库状态,它不是消息传递机制。

    这意味着如果您在一个节点上附加一个侦听器,您将获得该节点下的所有数据。如果您只想要新数据,则必须定义“新”的含义。

    例如:如果 new 表示附加侦听器后添加的数据,那么您可能希望在子节点中添加时间戳并对其进行过滤。

    或者,您可以只请求最近的 child_added 事件。我不确定如何使用您正在使用的 Python 库来执行此操作,但在 JavaScript 中它将是 firebase.database().ref('accelerometerData/faultyMotorData').orderByKey().limitToLast(1).on('child_added'...

    另见:

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 2017-03-15
      • 2016-09-17
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-14
      相关资源
      最近更新 更多