How to delete a specific child in Firebase?

0

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?

    
asked by anonymous 16.03.2018 / 19:52

2 answers

1

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) {

            }
        });
    
16.03.2018 / 21:07
1

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) {
 }
});
    
20.03.2018 / 13:41