0
I want to recover all users' followers in firebase.
I have the following structure at Firebase:
-seguidores
-id amigo
-id usuario
For that structure I did the following to retrieve it:
public void onDataChange(DataSnapshot dataSnapshot) {
//Recupera dados de usuário logado
usuarioLogado = dataSnapshot.getValue( Usuario.class );
/*
* Recuperar seguidores */
DatabaseReference seguidoresRef = firebaseRef
.child("seguidores")
.child( idUsuarioLogado );
seguidoresRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
seguidoresSnapshot = dataSnapshot;
dialog.cancel();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
And I went like this:
for( DataSnapshot seguidores: seguidoresSnapshot.getChildren() ){}
In this way I recover all through user id.
Now if my structure were like this:
-usuarios
-id usuario
Using this snippet of code:
DatabaseReference usuariosRef = firebaseRef
.child("usuarios");
usuariosRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
usuariosSnapshot = dataSnapshot;
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
How I would make a for to recover the ids of this type of structure?