1

I am trying to remove a dictionary element in firebase

enter image description here

I want to remove the object :-

D8QmnOSH6vRYiMujKNXngzhdn992: "True" at PendingFriendRequests/RhiZYyMF7STn1vyA27HjnJRsLYb2 so far i have come up with this :-

FIRControllerClass.ref.child("PendingFriendRequests").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEventOfType(.Value, withBlock: {(Snapshot) in

                        let dict = Snapshot.value! as! NSMutableDictionary

                        for each in dict {
                        print(each)

                            print(acceptedFriend)

                            if each.key as! String == acceptedFriend{
                                print(each.key)
                                dict.removeObjectForKey(each.key)
                                print(dict)
                                }
                            FIRControllerClass.ref.child("PendingFriendRequests").child(acceptedFriend).setValue(dict)
                            }
                        })
Dravidian
  • 9,945
  • 3
  • 34
  • 74
  • Sounds good. What problem are you having? https://firebase.google.com/docs/database/ios/save-data#delete_data – Frank van Puffelen Jul 19 '16 at 19:32
  • how do i define a path for a dictionary element inside a child? – Dravidian Jul 19 '16 at 19:36
  • 1
    `ref.child("PendingFriendRequests/RhiZYyMF7STn1vyA27HjnJRsLYb2/D8QmnOSH6vRYiMujKNXngzhdn992").removeValue()` – Frank van Puffelen Jul 19 '16 at 19:39
  • Just a quick Q. (not of the same topic), is it okay to use two backend in the same app? i am using Cloudinary for images that users post and firebase for basic database like userProfile , posts, update...etc – Dravidian Jul 19 '16 at 19:50
  • That's fine. Storing user data in one place and static content like images in another is very common. – dan Jul 19 '16 at 20:15

2 Answers2

0

https://firebase.google.com/docs/firestore/manage-data/delete-data?authuser=0

var cityRef = db.collection('cities').doc('BJ');

// Remove the 'capital' field from the document
var removeCapital = cityRef.update({
    capital: firebase.firestore.FieldValue.delete()
});
Iskeraet
  • 731
  • 1
  • 6
  • 12
-1

var ref: DatabaseReference!

ref = Database.database().reference()

FIRControllerClass.ref.child("parentKey").child("childKey").setValue(nil)