这是我的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()
中,我有钥匙。
答案 0 :(得分:2)
尝试像这样更改删除功能
dB.Child("/Contacts/"+key).Remove()