Reputation: 35
How to remove one Item in the database of the fire base?
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
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
Reputation: 80944
Change the query to the following :
Query appQuery = ref.child("Markers").orderByKey().equalTo(firebaseAuth.getUid());
Upvotes: 0