0

What is the appropriate code to delete records by Specific value from android studio .
Required: Delete all records If starCount field equal 0.

private void deleteData(String strTitle){ } 

enter image description here

1 Answer 1

2

In order to delete a node you need to know its full path. This means you you'll need to run a query to find the node with starCount equal to 0 and then delete each of them individually.

Something like this:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("posts"); Query query = ref.orderByChild("starCount").equalTo(0); query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) { postSnapshot.getRef().removeValue(); } } @Override public void onCancelled(DatabaseError databaseError) { throw databaseError.toException(); } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much Frank van Puffelen 100%. How to update the (title field) condition (starCount =0 and body="d1")
StackOverflow is not a site which does your homework. Please do some research on Firebase Database

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.