Josh
Josh

Reputation: 254

How to delete an object with multiple children in Firebase?

I am trying to delete an object with multiple children in my Firebase database. My data is setup like so:

Attempting to delete, -KK4kr7tBDN-2whVrjbJ

I am running the following code in my iOS app:

[[ref child:[NSString stringWithFormat:@"/playlistSongs/%@", playlistObject[@"firebaseID"], nil]] removeValueWithCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {
                        if (error) {
                            NSLog(@"ERROR: %@", error.localizedDescription);
                        } else {
                            NSLog(@"DELETED!");
                        }
                    }];

When this code runs, DELETED! is outputted in the log. However the object still remains in my firebase database. Is it possible to delete objects with multiple children? Looking at the documentation here, it suggests that I should be able to do so. It would be great if someone could point me in the right direction.

Upvotes: 0

Views: 2522

Answers (3)

Raynaldio Limarga
Raynaldio Limarga

Reputation: 51

remove value function is work for me

[[[_ref child:@"playlistSongs"] child:snapshot.key] removeValue];

Upvotes: 1

Jay
Jay

Reputation: 35677

Sometimes simpler is better:

Firebase *ref = path to the parent node
[ref setValue: nil];

Upvotes: 3

Trong Dinh
Trong Dinh

Reputation: 363

It should be better if you stand "playlistSongs" and call updateChildValues with nil param.

Upvotes: 0

Related Questions