dongluoheng3324 2017-02-09 10:57
浏览 16
已采纳

如何使用Golang在Firebase中搜索特定值?

I am using Golang and Firego for connecting to Firebase. I am trying to search an admin with Email: john@gmail.com. The following is my Database Structure

My Firebase Database Structure

For this I have tried:

  dB.Child("CompanyAdmins").Child("Info").OrderBy("Email").EqualTo("john@gmail.com").Value(&result)

but it does not produce expected result. How can I do this?

  • 写回答

3条回答 默认 最新

  • doutan1905 2017-02-09 14:50
    关注

    While @dev.bmax has the problem identified correctly, the solution is simpler. You can specify the path of a property to order on:

      dB.Child("CompanyAdmins")
        .OrderBy("Info/Email")
        .EqualTo("john@gmail.com")
        .Value(&result)
    

    Update (2017-02-10):

    Full code I just tried:

    f := firego.New("https://stackoverflow.firebaseio.com", nil)
    
    var result map[string]interface{}
    
    if err := f.Child("42134844/CompanyAdmins").OrderBy("Info/Email").EqualTo("john@gmail.com").Value(&result); err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("%s
    ", result)
    

    This prints:

    map[-K111111:map[Info:map[Email:john@gmail.com]]]

    Which is the exact place where I put the data.

    Update 20170213:

    This is the index I have defined:

      "CompanyAdmins": {
        ".indexOn": "Info/Email"
      }
    

    If this doesn't work for you, please provide a similarly complete snippet that I can test.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失