简体   繁体   English

从Firebase数据库中删除值

[英]Removing a value from Firebase Database

I am trying to remove a value within the Firebase Realtime Database. 我正在尝试删除Firebase实时数据库中的值。 Here is the code I am using: 这是我正在使用的代码:

FIRDatabase.database().reference()
           .child(FIRAuth.auth()!.currentUser!.uid).child("instagramLink")
           .removeValue()

Here is the JSON Data Structure: 这是JSON数据结构:

Users {

    userUID {

        email: "test@test.com"
        fullName: "John Doe"
        instagramLink: "testLink"
    }
}

I am telling the database to remove the key "instagramLink", which I know is currently in the database, but the key never gets removed. 我告诉数据库删除密钥“instagramLink”,我知道它目前在数据库中,但密钥永远不会被删除。

How do I remove the key? 如何删除密钥?

Extending to @cartant's answer , this way you will know if you run along any error during removal or if the value's were removed successfully or not.:) 扩展到@ cartant的答案,这样您就可以知道在删除过程中是否运行了任何错误,或者是否成功删除了值。:)

FIRDatabase.database().reference().child(Users).child(FIRAuth.auth()!.currentUser!.uid).child("instagramLink").removeValueWithCompletionBlock({ (error, refer) in
if error != nil {
 print(error)
   } else {
  print(refer)
 print("Child Removed Correctly")
}

It looks like you've left Users out of the path: 您似乎已将Users排除在路径之外:

FIRDatabase.database()
    .child("Users")
    .child(FIRAuth.auth()!.currentUser!.uid)
    .child("instagramLink")
    .removeValue()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM