运行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"
}
答案 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"]
}
}
}
}