我的.indexOn规则已添加到安全性&规则没有考虑在内 [英] My .indexOn rule added to Security & Rules isn't taken into account

查看:84
本文介绍了我的.indexOn规则已添加到安全性&规则没有考虑在内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我的数据:



获取 https://testindexon.firebaseio.com/.json p>

{
key1:{
age:80,
name:zabc
key2:{
age:90,
name:defg
},
key3: {
age:10,
name:hijk
}
}



以下是我的安全规则:

$ brules:{
.read:true,
.write:true,
testindexon:{
.indexOn:age
}
}




$ b当我尝试使用索引的age属性命令时,出现错误:



获取 https:/ /testindexon.firebaseio.com/.json?orderBy= 年龄



错误400(错误的请求)



$ {
error:Index not defined
}



我可以通过重写我的安全规则来解决400错误:
$ b $ p $ {
rules :{
.read:true,
.write:true,
.indexOn:[age,name]
}
}



但是当我尝试通过其中一个属性进行排序时,没有发生特殊情况(结果未排序):

GET ... firebaseio.com/.json?orderBy=\"age



< code $ {
key1:{
age:80,
name:zabc
},
key2: {
age:90,
name:defg
},
key3:{
age:10,
name:hijk
}
}



我将不胜感激任何帮助。

Best,

状态变量

解决方案

根据
$ b


REST API返回的不确定结果



JSON解释器不会对结果集执行任何排序。虽然orderBy可以与startAt,endAt,limitToFirst或limitToLast结合使用来返回数据的一个子集,但返回的结果将不会被排序。因此,如果排序很重要,可能需要手动排序结果。

似乎有其他建议。但是上面的语句是真实的。



请记住, orderBy 参数用于更多的事情, em>返回命令的结果。你也可以使用这个方法来过滤结果,例如:

$ $ $ code> GET'https://testindexon.firebaseio.com/。 json?orderBy =age& equalTo = 90'

或者你会命令返回一个有限结果数量:

  GET'https://testindexon.firebaseio.com/.json?orderBy=\"age\"&因此,在这些情况下,子节点在服务器上进行排序,然后进行筛选,但返回值将仍然可能包含未定顺序的剩余子节点。


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

解决方案

According to the Firebase documentation on retrieving data through its REST API:

THE REST API RETURNS UNSORTED RESULTS

JSON interpreters do not enforce any ordering on the result set. While orderBy can be used in combination with startAt, endAt, limitToFirst, or limitToLast to return a subset of the data, the returned results will not be sorted. Therefore, it may be necessary to manually sort the results if ordering is important.

There are indeed samples and others fragments in that documentation that seem to suggest otherwise. But the above statement is true.

Keep in mind that the orderBy parameter is used for more things than just returning ordered results. You'd also use the method to filter the results, i.e.

GET 'https://testindexon.firebaseio.com/.json?orderBy="age"&equalTo=90'

Or you would order to return a limited number of results:

GET 'https://testindexon.firebaseio.com/.json?orderBy="age"&limitToFirst=10'

So in these cases, the child nodes are sorted on the server and then filtered, but the return value will/may still contain the remaining child nodes in an undetermined order.

这篇关于我的.indexOn规则已添加到安全性&amp;规则没有考虑在内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆