【问题标题】:Removing a dictionary element in Firebase在 Firebase 中删除字典元素
【发布时间】:2016-11-22 20:21:17
【问题描述】:

我正在尝试删除 firebase 中的字典元素

我想删除对象:-

D8QmnOSH6vRYiMujKNXngzhdn992: "True"PendingFriendRequests/RhiZYyMF7STn1vyA27HjnJRsLYb2 到目前为止,我想出了这个:-

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)
                            }
                        })

【问题讨论】:

  • 听起来不错。你有什么问题? firebase.google.com/docs/database/ios/save-data#delete_data
  • 我如何为孩子内部的字典元素定义路径?
  • ref.child("PendingFriendRequests/RhiZYyMF7STn1vyA27HjnJRsLYb2/D8QmnOSH6vRYiMujKNXngzhdn992").removeValue()
  • 只是一个快速的问题。(不是同一个主题),可以在同一个应用程序中使用两个后端吗?我将 Cloudinary 用于用户发布的图像,并将 firebase 用于基本数据库,如 userProfile、帖子、更新...等
  • 没关系。将用户数据存储在一个地方,将静态内容(如图像)存储在另一个地方非常常见。

标签: ios swift dictionary firebase-realtime-database


【解决方案1】:

var ref: 数据库引用!

ref = Database.database().reference()

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

【讨论】:

    【解决方案2】:

    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()
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2011-08-16
      • 2019-08-22
      • 1970-01-01
      • 2016-05-06
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多