嵌套 属性 的 Firebase indexOn

Firebase indexOn for a nested property

我的数据库结构是这样的:

 {
   "Products" : {
     "0100251633" : {
       "codes" : {
         "Call" : "000156",
         "EAN13" : "7898613211028"
       },
       "productid" : "0100251633",
       "nmproduct" : "BRW 12 COLOR HYDROGRAPHIC PEN",
       "quantity" : 0,
       "stativo" : "S",
       "url" : "SemUrl"
     }
   }
 }

我需要通过“调用”代码对我的数据库进行排序(索引)。

有效的规则(按描述排序)是这个:

 {
   "rules": {
     ".read": "auth.uid != null",
     ".write": "auth.uid != null",
       "Products":{
         ".indexOn": ["nmproduct","codes","Call"]
       }
   }
 }

但是我需要通过调用代码来排序。我正在尝试这种方式,因为这是我的理解方式:

 {
   "rules": {
     ".read": "auth.uid != null",
     ".write": "auth.uid != null",
       "Products":{
         "Codes":{
             ".indexOn": ["Call"]
         }
       }
   }
 }

它不起作用,我得到下面的 return:

 raise HTTPError(e, request_object.text)
 requests.exceptions.HTTPError: [Errno 400 Client Error: Bad Request for url:           https://inventarioshop-8318f-default-rtdb.firebaseio.com/Produtos.json?     auth=65465465465465465465465465&orderBy=%22Chamada%22] {
    "error" : "Index not defined, add \".indexOn\": \"Call\", for path \"/Products\", to the rules"
  }

非常感谢您帮助我理解并向其他人解释。

要在节点下索引嵌套的 属性,您需要在索引定义中指定 属性 的路径。

所以您的呼叫代码是:

"Products":{
  ".indexOn": ["nmproduct","codes/Call"]
}