"Index not defined" 使用 Firebase JSON API
"Index not defined" when using Firebase JSON API
当 运行 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"
}
根据您的示例数据和查询,indexOn
定义应位于 $user
对象下,因为 userTimestamp
字段位于 /moodlogNumbers/$user/userTimestamp
.
{
"rules": {
"moodlogNumbers": {
"$user": {
".write": "auth != null && auth.uid == $user",
".read": "auth != null && auth.uid == $user",
".indexOn": ["userTimestamp"]
}
}
}
}
当 运行 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"
}
根据您的示例数据和查询,indexOn
定义应位于 $user
对象下,因为 userTimestamp
字段位于 /moodlogNumbers/$user/userTimestamp
.
{
"rules": {
"moodlogNumbers": {
"$user": {
".write": "auth != null && auth.uid == $user",
".read": "auth != null && auth.uid == $user",
".indexOn": ["userTimestamp"]
}
}
}
}