Delete Records From Google Firebase Realtime Database
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 str
Solution 1:
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:
DatabaseReferenceref= FirebaseDatabase.getInstance().getReference("posts");
Queryquery= ref.orderByChild("starCount").equalTo(0);
query.addListenerForSingleValueEvent(newValueEventListener() {
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
postSnapshot.getRef().removeValue();
}
}
@OverridepublicvoidonCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
}
Post a Comment for "Delete Records From Google Firebase Realtime Database"