firebase - orderBy 上的 Firestore 查询崩溃?
问题描述
我正在使用 Flutter Firebase SDK。当我使用这个复合查询时,它会导致错误:
.where('field', whereNotIn: [‘data’])
.where('otherfield}',
isEqualTo: anotherField),
.orderBy(‘timestamp’, descending: false),
解析查询参数时发生错误,这很可能是此 SDK 的错误。(
如果我删除 orderBy,则不会崩溃。例如:
.where('field', whereNotIn: [‘data’])
.where('otherfield}',
isEqualTo: anotherField),
// .orderBy(‘timestamp’, descending: false),
作品^
为什么?
感谢帮助!
解决方案
如果您包含具有范围比较(<、<=、>、>=)的过滤器,则您的第一个排序必须在同一字段上有效:
citiesRef.where("population", ">", 100000).orderBy("population")
无效的:
citiesRef.where("population", ">", 100000).orderBy("country")
我刚刚成功修复的错误示例错误:
.whereEqualTo("restaurantID", resRef)
.whereNotEqualTo("image", "")
.orderBy("createdAt", Query.Direction.DESCENDING)
正确的:
.whereEqualTo("restaurantID", resRef)
.whereNotEqualTo("image", "")
**.orderBy("image", Query.Direction.ASCENDING)**
.orderBy("createdAt", Query.Direction.DESCENDING).get()
https://firebase.google.com/docs/firestore/query-data/order-limit-data
推荐阅读
- node.js - 使用 Node.js 查询连接两个 Postgres 数据库表
- c++ - unique_ptr 和 shared_ptr 的重载方法与多态性不明确
- ssl - ionic 应用服务器设置的 https 设置
- angular - 如何将 dx-data-grid 及其工具包装到另一个组件中并使其成为控制器?
- java - java.text.ParseException - 格式正确
- delphi - Delphi 远程调试器无法通过 WAN 连接工作
- database - wix 安装程序工具集中的 ComboBox 上的自定义操作删除/添加
- android - 一段时间后,AsyncTask 在服务中变慢
- python - 如何从多列中返回一个分组列的平均值
- sabre - 创建乘客姓名记录 - 消息 NO FARE FOR CLASS USED