如何使用golang从Firebase删除密钥?

时间:2017-01-24 06:19:10

标签: go firebase firebase-realtime-database

这是我的Firebase结构。

Contacts

{
  "-Kav_cy_EFZnu5vNWP2g" :

 {

    "Address" : "dfsswrfdssddsd",
    "CurrentDate" : 1484910921411,
    "Email" : "a@fg.hh",
    "Name" : "abc",
    "PhoneNumber" : "53465465765677",
    "State" : "fdsf",
    "Status" : "Completed",
    "Zipcode" : "43434"
  },


  "-Kb9ghONh670tUOkOG3N" :

 {


    "Address" : "jfhjhfjfj",
    "CurrentDate" : 1485164432603,
    "Email" : "fg@gmail.com",
    "Name" : "dcf",
    "PhoneNumber" : "9897878787",
    "State" : "fdsf",
    "Status" : "Completed",
    "Zipcode" : "56546"


  }
}

我想删除与密钥(-Kav_cy_EFZnu5vNWP2g)对应的数据。我试过下面的代码,但它不起作用:

模型

func (m *User) DeleteFromDB(ctx context.Context,key string)(bool)  {


    dB, err := GetFirebaseClient(ctx,"")
    if err!=nil{
        log.Println("Connection error:",err)
    }
    err = dB.Child(key).remove();
    if err!=nil{
        log.Println("Deletion error:",err)
        return false
    }
 return true


}

DeleteFromDB()中,我有钥匙。

1 个答案:

答案 0 :(得分:2)

尝试像这样更改删除功能

dB.Child("/Contacts/"+key).Remove()