考虑为Firebase添加.indexOn

时间:2016-11-28 05:55:49

标签: android firebase firebase-realtime-database firebase-security

我有一个Firebase数据库:

 "requested_rides" : {
"2016-10-04" : {
  "-KT9F_8DJHmKj33PW70w" : {
    "added_on" : 1475493385140,
    "code" : "AQZ66I4QP4",
    "date_of_ride" : "2016-10-04 AD 04:22 AM GMT+05:45",
    "day" : "Tomorrow",
    "dropoff_coordinate" : "27.6953541,85.2965062",
    "dropoff_location" : "Chunne Pakha",
    "fullname" : "bhaskarraj93@gmail.com",
    "offered_by" : "v1tENP2TaUVHaZFhSGuZ4M6cJJU2",
    "pickup_coordinate" : "27.716454540107783,85.32458111643793",
    "pickup_location" : "Kuber Plazza, Kathmandu 44600, Nepal",
    "seats" : "2",
    "share" : "578",
    "time" : "04:22 AM",
    "vechile_type" : "Bike"
  }
},

我已将规则添加到数据库但我收到此错误

考虑在/ requested_rides / 2016-11-23添加".indexOn": "code"到您的安全和Firebase规则以获得更好的效果

我定义的规则是

"rules":{
    ".read":true,
    ".write":true,
    "requested_rides":{
        ".indexOn":"code"
    }
}

2 个答案:

答案 0 :(得分:3)

错误消息告诉您将索引添加到/requested_rides/2016-11-23。所以这将更深一层:

"rules":{
    ".read":true,
    ".write":true,
    "requested_rides":{
        "2016-11-23": {
            ".indexOn":"code"
        }
    }
}

或(更有可能):

"rules":{
    ".read":true,
    ".write":true,
    "requested_rides":{
        "$date": {
            ".indexOn":"code"
        }
    }
}

这意味着只有在您知道骑行日期后才能查询游乐设施。

答案 1 :(得分:0)

您以另一种方式定义indexOn,请尝试改为:

Button