-1

enter image description here

enter image description here

I want to delete apple in breakfast separately, but the above method will delete all apples, regardless of whether it is breakfast, lunch, or dinner. Is there any solution? Thank you

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

There is no way to add this second condition to the query, as Firebase Realtime Database can only query on one property. See Query based on multiple where clauses in Firebase

If you want to only delete a subset of the items returned by the query, you'll have to check for the addition condition in your loop:

for (DataSnapshot data: snapshot.getChildren()) {
  if ("apple".equals(data.child("foodname").getValue(String.class))) {
    data.getRef().removeValue();
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807