是否有可能以这种方式获取此数据库结构的数据?

时间:2018-06-02 00:51:00

标签: typescript firebase firebase-realtime-database angularfire2

我有这样的结构:

"games" : {
    "03e46939-af4e-4b9a-ba3b-99132f0bf34d" : {
      "1P0mWbp1jYOayaMEyQcnKvX4YB63" : {
        "logs" : {
          "-LDxpYtVZJc4LmJmyzn1" : {
            "guess" : "1234",
            "result" : "1P 1B",
            "score" : 150
          }
        },
        "maxbulls" : 1,
        "maxpigs" : 1,
        "moves" : 1,
        "profilepicture" : "bull.png",
        "score" : 150,
        "username" : "user1p0mw"
      },
      "5AvSPiyH3faqw1P7inHdyjV6noC2" : {
        "maxbulls" : 0,
        "maxpigs" : 0,
        "moves" : 0,
        "profilepicture" : "pig.png",
        "score" : 0,
        "username" : "user5avsp"
      },
      "answer" : "8103e4693964",
      "id" : "03e46939-af4e-4b9a-ba3b-99132f0bf34d",
      "requestor" : "1P0mWbp1jYOayaMEyQcnKvX4YB63",
      "status" : "pending",
      "turn" : ""
    },
    "21b1451-rf45-4b9a-ba3b-99132fgoe856" : {
      "5AvSPiyH3faqw1P7inHdyjV6noC2" : {
        "logs" : {
          "-LSwzYtVZJp9s6gmuw7n" : {
            "guess" : "1234",
            "result" : "1P 1B",
            "score" : 150
          }
        },
        "maxbulls" : 1,
        "maxpigs" : 1,
        "moves" : 1,
        "profilepicture" : "pig.png",
        "score" : 150,
        "username" : "user5avsp"
      },
      "answer" : "8103e4693964",
      "id" : "21b1451-rf45-4b9a-ba3b-99132fgoe856",
      "requestor" : "5AvSPiyH3faqw1P7inHdyjV6noC2",
      "status" : "pending",
      "turn" : ""
    }
  }

有许多游戏具有唯一的GUID且包含1-2个UID的键。我希望得到5AvSPiyH3faqw1P7inHdyjV6noC2是游戏孩子的所有游戏。我在查询时知道游戏ID。

我已经尝试了this.afDatabase.list('/games/', ref => ref.orderByChild(user.uid)),这导致所有游戏被拉入。编辑:无论传递什么UID。我意识到这个例子很糟糕,因为在这种情况下我会想要返回所有游戏。

并且this.afDatabase.list('/games/', ref => ref.orderByChild(user.uid).equalTo(user.uid))没有游戏。

this.afDatabase.list('/games/', ref => ref.orderByChild().equalTo(user.uid))会抛出关于orderByChild没有传递任何参数的错误。

0 个答案:

没有答案