查询firebase中嵌套较深的子级

querying deeply nested children in firebase

本文关键字:firebase 嵌套 查询      更新时间:2023-09-26

给定以下数据结构(从firebase导出):

{
"users" : {
  "123456789" : {
    "email" : "test@gmail.com",
    "name" : "test",
       "listings" : {
          "adtitle" : {
            "description" : "this is a description",
            "skilltype" : "painter"
          },
          "adtitle2" : {
            "description" : "this is a second description",
            "skilltype" : "painter"
          }
       }
    }
  }
}

我想运行以下查询:

var ref = new Firebase("https://my.firebaseio.com/users");
ref.orderByChild("listings/adtitle/skilltype").equalTo("painter").on("child_added", function(snapshot) {
    console.log(snapshot.key());
});

但是在控制台上得到以下错误:

Error: Query.orderByChild failed: First argument was an invalid key: "listings/adtitle/skilltype".  Firebase keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]").

有人看到我哪里错了吗?我认为这是在firebase中查询嵌套数据的正确方法?

Firebase JavaScript SDK 2.3中引入了查询深层属性的功能。如果你的目标是Android或iOS,该功能是在这些SDK的2.4版本中引入的。

请确保您使用的是该版本(或更新的版本)。

请注意,我不认为这是一个答案,但这个问题反复出现(请参阅昨天的这个),如果没有答案,我就无法标记重复的问题