gpt4 book ai didi

firebase - Firestore 按两个字段排序

转载 作者:行者123 更新时间:2023-12-03 06:32:23 24 4
gpt4 key购买 nike

在firestore中,我想知道是否有一种方法可以拥有hueristic1并获取两个hueristic1值之间的所有数据,但根据hueristic2对结果进行排序。

我问是因为两页底部都有数据

https://firebase.google.com/docs/firestore/query-data/order-limit-data

https://firebase.google.com/docs/firestore/query-data/query-cursors

文档似乎有些矛盾。

我想要做的是

Ref.startAt(some h1 value).endAt(some second h1 value).orderBy(h2).  

我知道我可能必须按 h1 进行索引,但即便如此,我也不确定是否有办法做到这一点。

最佳答案

更新:

我没有对此进行足够好的测试,看不到它不会产生所需的排序。 OP asked the question again并从 Firebase 团队成员那里得到了答案:

Because Cloud Firestore doesn't support ordering by a different field than the supplied inequality, you won't be able to sort by name directly from the query. Instead you'd need to sort client-side once you've fetched the data.

<小时/>

API 支持您想要的功能,尽管我在文档中没有看到显示它的示例。

查询词的顺序很重要。假设您有一个城市集合,感兴趣的字段是 population (h1) 和 name (h2)。要获取人口在 1000 到 2000 之间的城市(按名称排序),查询如下:

citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)

此查询需要复合索引,您可以在控制台中手动创建该索引。或者正如文档所示,系统将帮助您:

Instead of defining a composite index manually, run your query in your app code to get a link for generating the required index.

关于firebase - Firestore 按两个字段排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47381713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com