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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)