I want to exclude only the 1st child (L7jrJ6DtQWrmZsC4zvT) from Firebase through an option in an Android app. I searched several places and could not find it. I only found the option to delete the entire database. Can anyone help?
You will have to read and then delete. Use limitToFirst()
, passing 1 to get only the first child:
calendarioRef.limitToFirst(1).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String childKey = dataSnapshot.getKey();
calendarioRef.child(childKey).removeValue();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
I got the following code:
Query queryRemoverCalendario = mCalendarioDatabaseReference.limitToFirst(1);
queryRemoverCalendario.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot removerCalendarioSnapshot : dataSnapshot.getChildren()) {
removerCalendarioSnapshot.getRef().removeValue();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});