Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
863 views
in Technique[技术] by (71.8m points)

firebase - My .indexOn rule added to Security & Rules isn't taken into account

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...