Query a specific child node in all instances of a parent node in Firebase

后端 未结 2 1296
终归单人心
终归单人心 2021-01-26 23:27

I\'m trying to figure out how, if possible, to query a specifically named child node in all instances of a parent node in Firebase. It can be assumed that all parent nodes queri

2条回答
  •  天涯浪人
    2021-01-26 23:50

    When you load a node from Firebase, you also get all data under that node. Assuming that you have more data per user than just their display name, that can indeed lead to needlessly loaded data.

    If you only want to load a list of display names, you should indeed store a list of display names.

    {
      displayNames: {
        "stringOfSomeKind": "uid",
        "moreStrings": "uid2",
        "evenMoreStrings": "uid3"
      }
    }
    

    If you come from a background of relational/SQL databases, this may seem unnatural at first. For me it helped to realize that these structures are indexes, same as the "index by displayName" that you might add to your relational database. The difference is that in NoSQL/Firebase it is your code that maintains the index, while in most RDBMSs such indexes are maintained by the system.

提交回复
热议问题