【问题标题】:How to select data from firebase realtime database如何从 Firebase 实时数据库中选择数据
【发布时间】:2017-12-04 21:42:46
【问题描述】:

我有一个结构大致类似的数据库

// An index to track Ada's memberships
{
  "users": {
    "alovelace": {
      "name": "Ada Lovelace",
      // Index Ada's groups in her profile
      "groups": {
         // the value here doesn't matter, just that the key exists
         "techpioneers": true,
         "womentechmakers": true
      }
    },
    ...
  },
  "groups": {
    "techpioneers": {
      "name": "Historical Tech Pioneers",
      "members": {
        "alovelace": true,
        "ghopper": true,
        "eclarke": true
      }
    },
    ...
  }
}

但我不知道如何选择属于同一组成员的用户

【问题讨论】:

  • 到目前为止您尝试过什么?分享一些代码。

标签: android firebase-realtime-database nosql


【解决方案1】:

您必须定义一个额外的 group_combinationsall_groups 索引,将每个用户存储在他们组合的组下:

all_groups: {
  "techpioneers_womentechmakers": {
    alovelace: true
  }
}

【讨论】:

  • 对,最简单的版本,也在想,想不出更好的了。我将尝试通过云功能使组组合自动更改
  • 是的,这确实是我更喜欢在服务器端做的事情之一。还要确保按字母顺序对类别名称进行排序,这样即使它们以不同的顺序到达,您也可以获得一致的结果。
猜你喜欢
  • 1970-01-01
  • 2018-09-11
  • 2021-07-18
  • 2018-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多