"索引未定义"使用Firebase JSON API时

时间:2015-03-06 19:36:11

标签: json firebase

运行https://moodtrackerapp.firebaseio.com/moodlogNumbers/simplelogin:40.json?orderBy="userTimestamp"&auth=TOKEN_REMOVED时,即使我在规则中设置了索引,也没有从API定义索引。

我的数据结构:

"moodlogNumbers": {
    "simplelogin:1": {
        {
            "-Jin5iKQ_thuHueDOTxn": {
                "level": 9,
                "serverTimestamp": 1424639059798,
                "userTimestamp": 1424639059530
            }
        }
    }
}

我的安全规则:

{
    "rules": {
      "moodlogNumbers": {
        ".indexOn": ["userTimestamp"],
        "$user": {
          ".write": "auth != null && auth.uid == $user",
          ".read": "auth != null && auth.uid == $user"
        }
      }
    }
}

我还注意到从文档中尝试此查询时:

curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="height"&print=pretty'

我得到了相同的结果:

$ curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="height"&print=pretty'
{
  "error" : "Index not defined"
}

1 个答案:

答案 0 :(得分:3)

根据您的示例数据和查询,indexOn定义应位于$user对象下,因为userTimestamp字段位于/moodlogNumbers/$user/userTimestamp

{
  "rules": {
    "moodlogNumbers": {
      "$user": {
        ".write": "auth != null && auth.uid == $user",
        ".read": "auth != null && auth.uid == $user",
        ".indexOn": ["userTimestamp"]
      }
    }
  }
}