Firebase按字段筛选并按其他字段排序
我在Firebase中有一个数据库,其中包含以下数据:Firebase按字段筛选并按其他字段排序,firebase,firebase-realtime-database,Firebase,Firebase Realtime Database,我在Firebase中有一个数据库,其中包含以下数据: { user: 1; points: 100; }, { user: 1; points: 510; }, { user: 2; points: 110; }, { user: 1; points: 85; }, { user: 3; points: 300; }, { user: 1; points: 500; } 如何进行查询,使其仅显示用
{
user: 1;
points: 100;
},
{
user: 1;
points: 510;
},
{
user: 2;
points: 110;
},
{
user: 1;
points: 85;
},
{
user: 3;
points: 300;
},
{
user: 1;
points: 500;
}
如何进行查询,使其仅显示用户1的字段,并使用REST查询从最高到最低排序
我试过了
https://xxxxxx.firebaseio.com/tirada.json?orderBy="user"&equalTo="1"
它返回按用户过滤但不按点排序的结果
{
user: 1;
points: 100;
},
{
user: 1;
points: 510;
},
{
user: 1;
points: 85;
},
{
user: 1;
points: 500;
}
我需要这个结果
{
user: 1;
points: 85;
},
{
user: 1;
points: 100;
},
{
user: 1;
points: 500;
},
{
user: 1;
points: 510;
}
Thank的Firebase数据库查询只能对单个属性进行排序/筛选。在许多情况下,可以将要筛选的值组合到单个(合成)特性中。在您的情况下,这将转化为一个属性
“user\u points”:“1\u 510”
,然后您可以对其进行排序/筛选。
但是RESTAPI返回原始JSON对象,JSON对象中属性的顺序未定义。因此,这意味着您无论如何都必须根据客户端代码中的点值对结果进行排序。考虑到这一点,您可能还是坚持只对user
进行过滤
另见: