Home > Software engineering >  kotlin firebase remove child
kotlin firebase remove child

Time:11-14

I'm trying to delete a specific value from a firebase realtime database, but I don't know how to do it because I don't know to save or find the key value of the child which is automatically generate.

enter image description here

If you see the picture I've only managed to remove all the children from the first key with

FirebaseDatabase.getInstance().reference.child("Comentarios").removeValue()

But I need to delete just by the child creadoPor

Is there any way of skkiping an unnamed child?

FirebaseDatabase.getInstance().reference.child("Comentarios").removeValue()

But I need to delete just by the child creadoPor.

CodePudding user response:

Since you know the "grantparent" key of the data and the value of one of the nodes properties, you can use a query to find the nodes that match that value.

FirebaseDatabase.instance
  .ref("Comentarios")
  .child("-NGi7xP...")
  .orderByChild("creadoPor")
  .equalTo("R7lji3...")

When you get the DataSnapshot from the query, you'll need to loop over its children as shown in the documentation on listening for value events. Even when there's only one result, you'll get a list of one child node and thus will need to loop over them.

  • Related