I'm trying to set up custom indexes on my firebase data for sorting on certain fields.
Here is my data:
GET https://testindexon.firebaseio.com/.json
{
"key1": {
"age": 80,
"name": "zabc"
},
"key2": {
"age": 90,
"name": "defg"
},
"key3": {
"age": 10,
"name": "hijk"
}
}
Here are my security rules:
{
"rules": {
".read": true,
".write": true,
"testindexon": {
".indexOn": "age"
}
}
}
When I try to orderBy the indexed "age" property, I get an error:
GET https://testindexon.firebaseio.com/.json?orderBy="age"
Error 400 (Bad request)
{
"error": "Index not defined"
}
I can get around the 400 Error by rewriting my security rules as follows:
{
"rules": {
".read": true,
".write": true,
".indexOn": ["age", "name"]
}
}
But then when I try to order by one of the properties, nothing special happens (results aren't sorted):
GET ....firebaseio.com/.json?orderBy="age"
{
"key1": {
"age": 80,
"name": "zabc"
},
"key2": {
"age": 90,
"name": "defg"
},
"key3": {
"age": 10,
"name": "hijk"
}
}
Am I missing something ? I would appreciate any help.
Best,
State variable
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…