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

后端 未结 2 756
無奈伤痛
無奈伤痛 2020-12-04 03:19

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

<
相关标签:
2条回答
  • 2020-12-04 03:36

    It looks to me like your .indexOn is on the wrong path. You're fetching root, but put the .indexOn under the child path testindexon/. Thus, your URL would need to be https://testindexon.firebaseio.com/testindexon/.json in order to take advantage of the orderBy.

    0 讨论(0)
  • 2020-12-04 03:54

    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.

    0 讨论(0)
提交回复
热议问题