Tarvo Mäesepp Tarvo Mäesepp - 1 month ago 10
Swift Question

Firebase value not being deleted

I tried to delete one child from Firebase however it is not removing it for some reason.

That is how I tied to delete it(I get the right reference):

FIRDatabase.database().reference().child("posts").child(commentsArray[indexPath.row].key).removeValue()


If I try to
po
this value the output is e.g:


https://snuspedia.firebaseio.com/posts/coments/-KTzfD1wOa9sRXw93gAF


Which is this:enter image description here

Am I doing something wrong?

Answer

So what I recognize is that you miss the key of the post:

https://snuspedia.firebaseio.com/posts/<KEY OF YOUR POST>/comments/-KTzfD1wOa9sRXw93gAF

Reference code should include the key of the specific post:

FIRDatabase.database().reference().child("posts").child(<KEY OF YOUR POST>).child("comments").child(commentsArray[indexPath.row].key).removeValue()
Comments