How do I retrieve the selected node from firebase?
This is what my firebase database looks like
I want to access the accepting status of this node, for example, patient23. I can easily do this by using addlistenerforsingvalueevent on the accepting status and patient23 nodes respectively, But then I need two different requests to obtain the required data. I can also obtain the required data by adding a single request of addlistenerforsingvalueevent at the end of the parent node beacon, but that will retrieve a large amount of data because there are a large number of patients. How can I operate in a single request, but only retrieve the necessary nodes. Thank you
resolvent:
Firebase database is all a JSON object. If you select a part, all contents will be listed below
This means that you don't have to worry about making a request
Therefore, in your case, it is entirely feasible to make two separate "requests" for data, because there is no actual overhead to consider. The radio of the device is turned on, and the websocket header is only 6 bytes
You can easily create a listener on / accepting status and / patients / patient23. This is firebase standard practice with multiple listeners
// Get a root reference
Firebase rootRef = new Firebase("<my-firebase-app>");
// accepting-status ref
Firebase statusRef = rootRef.child("accepting-status");
// patient23 ref
Firebase patientRef = rootRef.child("patients").child("patient23");
// Listen for status updates
statusRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println(snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
// error
}
});
// Listen for patient updates
patientRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println(snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
// error
}
});