Firebase .indexOn嵌套项目

时间:2017-10-31 21:55:06

标签: firebase firebase-realtime-database

我现在正在努力让我的指数正确,但到现在为止没有运气..

我的数据库结构是:

(app name)
  + searches 
    + -Kw_Eyk6zbCcFklO119u (firebase random key) 
      + FlightOffers 
        + c6aa0d29-31b7-4113-81ab-8de2e4ee877e (firebase random key)
          + PricingOptions 
            + 0 
              + Price

在React中,我使用以下代码:

const searchRefOffers = firebase.database().ref('searches/' + this.Store.SearchStore.searchId + '/FlightOffers')

searchRefOffers.orderByChild("PricingOptions/Price").limitToFirst(100).on("value", (snapshot) => {
                firesnap = snapshot.val()
                writeFirebaseOffersToStore(firesnap)
            })

我的控制台一直说:

FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "PricingOptions/Price" at /searches/-KxoEfnwgJtMxzuIY2FJ/FlightOffers to your security rules for better performance. 

我使用以下规则:

{
    "rules": {
        ".read": true,
        ".write": true,
        "searches": {
            "$searchesid": {
                "FlightOffers": {
                    "$FlightOffersid": {
                        "PricingOptions": {
                            "0": {
                                ".indexOn": [
                                    "Price"
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
}

有人可以帮帮我吗?非常感谢!!

1 个答案:

答案 0 :(得分:0)

如果您使用 orderByChild() 则使用 $uid

{
  "rules": {
      ".read": true,
      ".write": true,
      "searches": {
          "$uid": {
              "FlightOffers": {
                  "$uid": {
                      "PricingOptions": {
                              ".indexOn": ["Price"]
                      }
                  }
              }
          }
      }
    }
}

如果您正在获取 orderByValue(),则以这种方式使用 Uid 对我有效,然后使用

{
  "rules": {
  "scores": {
     ".indexOn": ".value"
      }
  }
}