Screen shot of my Database
I would like to query my database by returning the names of all parents nodes which have certain similar child nodes.
I am already fetching the name of one parent with respect to it's child, but I want to fetch the name of all parents with similar child value.
Suppose, I want to get the names of the Hotels which have the similar child node value of 2000
and have a Rating of 3-star
.
final List<String> hotelNames = new ArrayList<String>();
final Query userQuery = FirebaseDatabase.getInstance().getReference().child("F-5").orderByChild("HotelTypeTwo");
userQuery.equalTo(varX).addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot foodSnapshot: dataSnapshot.getChildren()) {
hotelNames.add(foodSnapshot.getKey());
for (int i=0;i < hotelNames.size();i++)
{
Log.i("Value of element "+i,hotelNames.get(i));
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
}
);