I have below firebase database Structure.I am saving mobile no as child name. What I need to do is first get the tBid
value for each key having specific mobile no value equal to ok
then add/deduct a number and then update tBid
value for all key under b_ookk_node
I have tried below code so far but it is not working.How can I achieve this
final String mobile_no = singleToneClass.getInstance().getData();
mDatabasebook = FirebaseDatabase.getInstance().getReference().child("b_ookk_node");
Query ref_book = mDatabase.child(mobile_no).equalTo("ok");
ref_book.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()) {
for (DataSnapshot datas: dataSnapshot.getChildren()) {
final int total_bid = Integer.parseInt(datas.child("tBid").getValue(String.class));
String t_bid = Integer.toString(total_bid - 1);
mDatabasebook.child("tBid").setValue(t_bid);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});