user3711927
user3711927

Reputation: 35

How to remove one Item in the database of the fire base?

How to remove one Item in the database of the fire base?

enter image description here

I have code to delete the entire database:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Query applesQuery = ref.child("Markers").orderByChild(firebaseAuth.getUid());

applesQuery.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot appleSnapshot : dataSnapshot.getChildren()) {
            appleSnapshot.getRef().removeValue();
        }}
    @Override
    public void onCancelled(DatabaseError databaseError) {
        Log.e(TAG, "onCancelled", databaseError.toException());
    }
});

the picture shows that in the Marker database there are 2 entries and they have folded entries !!! How to delete one entry (logged in user), and the second should remain in the database ???

Upvotes: 0

Views: 57

Answers (2)

Abhinav Chauhan
Abhinav Chauhan

Reputation: 1394

As those keys are user id's you can do the following

FirebaseDatabase.getInstance().getReference()
.child("Markers")
.child(firebaseAuth.getUid())
.removeVaule();  

It will delete that node and folded data too

Upvotes: 1

Peter Haddad
Peter Haddad

Reputation: 80944

Change the query to the following :

Query appQuery = ref.child("Markers").orderByKey().equalTo(firebaseAuth.getUid());

Upvotes: 0

Related Questions