This may be duplicate Question but i have tries alot but i didnt get my result, Here is my firebase structure
Updated
I need to fin
As AlexMamo said you need to restructure database, i.e to flatten two levels hierarchy to only one level. As shown below:
Expense_Month
|
--- November_2018
|
--- 3_-LQ ... Gb
| |
| --- expensesName: "gross"
| |
| --- total: 66
| |
| --- day: "Monday"
| |
| --- day: 3
|
--- 4_-LQ ... LO
|
--- expensesName: "oil"
|
--- total: 33
|
--- day: "Tuesday"
|
--- day: 4
Notice each node in November_2018 is organised by the key formed by day followed by push Id separated by underscore. i.e "day_pushId". You can also add additional field for day (incase for particular day query is required). Then the query can be formed in the similar fashion as for "expensesName":
//Here monthyr is the November_2018
expensesaddref = databaseReference.child(username).child("Expense_Month").child(monthyr);
expensesaddref.orderByChild("expensesName").equalTo("oil").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.getChildrenCount() > 0){
Toast.makeText(getContext(), "Exist", Toast.LENGTH_SHORT).show();
}else
Toast.makeText(getContext(), "not", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});