duangua5742 2017-07-11 04:31
浏览 5
已采纳

我如何使用Golang中的特定密钥更新数据Firebase?

I am using golang and firego for connecting to Firebase. I want to update my data Statusfrom ON to OFF with key IDAgent: 7. This is my Database Structure

Image

Assumption : I don't know child active_chat. How can i update data in active_chat/-Koja8GuFplEN3kjbfPO where IDAgent = 7

I have tried this code

x := map[string]string{"Status": "OFF"}
ref.OrderBy("IDAgent").EqualTo("7").Update(x)

but this code wrong query.

  • 写回答

1条回答 默认 最新

  • duanfangfei5558 2017-07-11 05:29
    关注

    In two ways you can do, as per Firebase doc with firego client library. Drafted answer based on from firego README.md.

    Note: You have not provided the complete path of the structure, I have drafted the answer based on screenshot. So update your JSON path accordingly.

    Approach 1:

    f := firego.New("https://my-firebase-app.firebaseIO.com/active-chat/Koja8GuFpIEN3kjbfPO.json", nil)
    
    x := map[string]string{
       "Status": "OFF",
    }
    if err := f.Update(x); err != nil {
      log.Fatal(err)
    }
    

    Approach 2:

    f := firego.New("https://my-firebase-app.firebaseIO.com", nil)
    f = f.Ref("/active-chat/Koja8GuFpIEN3kjbfPO.json")
    
    x := map[string]string{
       "Status": "OFF",
    }
    if err := f.Update(x); err != nil {
      log.Fatal(err)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接