I want to recover all user followers on firebase.
I have the following structure in Firebase:
-seguidores
-id amigo
-id usuario
For this structure I did the following to recover 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 made a For as follows:
for( DataSnapshot seguidores: seguidoresSnapshot.getChildren() ){}
This way I retrieve all via the userid.
Now if my structure looks like this:
-usuarios
-id usuario
Using this code snippet:
DatabaseReference usuariosRef = firebaseRef
.child("usuarios");
usuariosRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
usuariosSnapshot = dataSnapshot;
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
How would I make a for to retrieve the ids of this type of structure?