问题
I currently have this python script running
# 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()
which is returning me the entire data under the respective node that I have my listener attached to.
But I require specifically only the newly added child under that node.
Any idea how could I achieve that???
回答1:
Firebase synchronizes database state, it is not a message passing mechanism.
This means that if you attach a listener on a node, you get all data under that node. If you only want new data, you'll have to define what "new" means.
For example: if new means data added after you attach a listener, then you may want to add a timestamp in your child nodes and filter on that.
Alternatively, you can request only the most recent child_added event. I'm not sure how to do that with the Python library you're using, but in JavaScript it would be firebase.database().ref('accelerometerData/faultyMotorData').orderByKey().limitToLast(1).on('child_added'...
.
Also see:
- How to retrieve only new data?
- How to only get new data without existing data from a Firebase?
- How to get only the new items added to firebase?
- Firebase child_added only get child added
来源:https://stackoverflow.com/questions/53303695/retrieve-only-childadded-from-firebase-to-my-listener-in-firebase