Q:

iOS - How To Remove Child From Multiple Parent Nodes In Firebase?

I have an app where an admin will make posts that create child posts under regular users. Every user can delete their own post, but I would like to make it so that the admin can remove a post as a sort of "Master Delete".
Currently, I can get the post to delete from the admin, but when the admin deletes, it only removes it from its own node. I made sure that the post would generate an "id" for itself so that I could use it to compare and trigger the delete check that way, but I'm not having much luck.
I found that if I use this code:
 DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").removeValue()
it will delete ALL posts from every user. 
However, if I observe with the postID with: DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").child(post.postId).setValue(nil)
It will delete from the admin account, but not the others.
My current code is:
guard let uid = Auth.auth().currentUser?.uid else { return }
let post = self.posts[indexPath.row]

DatabaseService.shared.REF_BASE.child("users").observeSingleEvent(of: .value, with: { (snapshot) in
    for child in snapshot.children {
        let snap = child as! DataSnapshot

        DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").child(post.postId).observe(.value, with: { (snapshot) in

            if DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").child(post.postId).child(post.uuid).key == DatabaseService.shared.REF_BASE.child("users").child(uid).child("posts").child(post.postId).child(post.uuid).key {
                DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").child(post.postId).setValue(nil)
            }
        })
    }     
})

Here is how my JSON tree is set up:
"users" : {
"fNST3lUqyzPtNqTlfCJ1BOMvBhl1" : {
  "email" : "test1@test.com",
  "first name" : "test1",
  "last name" : "test",
  "posts" : {
    "-L4noDwYVmQC7n0wVF9r" : {
      "date" : "2018-02-08 05:08:48 +0000",
      "imageURL" : "https://firebasestorage.googleapis.com/v0/b/learningfirebase-f8e28.appspot.com/o/postImages%2F6EAEA5E2-A687-4FC5-9234-929D4019A74F.jpg?alt=media&token=4cff25fa-9290-4e06-97cf-abf4d6c126bc",
      "isPending" : "false",
      "pair" : "",
      "price" : "",
      "signal" : "BUY",
      "uuid" : "-L4noDwPcvqjxTgDMzRl"
    },

Any advice? I've been struggling with this for hours and I can't seem to figure out what's going wrong here.

A:

I just solved this problem. I'm leaving the solution here in case it helps anyone else.
In my case, I needed to alter the way I added my data to the database. Initially, I was using:
DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").childByAutoId.setValue(parameters)

The problem with this is that Firebase was not able to iterate through and recognize the post ID's upon deletion. So I changed it to this:
DatabaseService.shared.REF_BASE.child("users").child(snap.key).child("posts").child(key).setValue(parameters)

The value of "key" is: 
let key = DatabaseService.shared.REF_BASE.child("users").child(snapshot.key).child("posts").childByAutoId().key

What this does is it gives each post the same Id when the value is added to the database. Then we can match it with the Id upon deletion. The same delete code I posted above works for what I want to do.
If this is unclear in any way, please let me know.

