【发布时间】:2021-09-01 03:35:10
【问题描述】:
我有一个复杂的查询要执行。我在我的 Firebase 项目中为此查询添加了一个复合索引。 这是查询。
FirebaseFirestore.instance
.collection('HouseDetails')
.where('housePrice', isGreaterThan: GV.price[0].ceil() - 1)
.where('housePrice', isLessThan: GV.price[1].ceil() + 1)
.where('houseArea', isGreaterThan: GV.area[0].ceil() - 1)
.where('houseArea', isLessThan: GV.area[1].ceil() + 1)
.where('bathrooms',
isEqualTo: int.parse(bathrooms.first).ceil() + 1)
.snapshots();
引发错误
I/flutter ( 9116): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 9116): The following assertion was thrown while handling a gesture:
I/flutter ( 9116): All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have
I/flutter ( 9116): inequality filters on 'FieldPath([housePrice])' and 'FieldPath([houseArea])'.
I/flutter ( 9116): 'package:cloud_firestore/src/query.dart':
I/flutter ( 9116): Failed assertion: line 484 pos 18: 'hasInequality == field'
阅读文档后,我了解到我无法一次过滤出多个字段类型。但我不明白如何执行需要多个字段进行比较的查询 (housePrice 和 houseArea 在我的例子中)。
如何执行这些查询?
【问题讨论】:
标签: firebase flutter google-cloud-firestore