I have a structure where I need to login with an user below a certain parent and I need to know in which parent I'm in order to modify that parent and my user id, here is my database structure
Now, Im login to the app with one of the users id below users node, now, I need to know the parent for that user in order to modify that user below that parent
Example
I login with the user RgF82BBZXhahtgYeZDWXwCk1q6b2
, now I need to know that is inside 9MmrGOJz9ePksi....
parent in order to add data inside that parent and inside that user
Tried this code but it only do it for a random key and not for the key containing that user
mDatabase.child("MyApp").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
String key = snapshot.getKey();
mDatabase.child("MyApp").child(key).child("users").child(mAuth.getCurrentUser().getUid()).child("apples").setValue("3");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});