这个问题在这里已经有了答案:
Query based on multiple where clauses in Firebase
(8 个回答)
1年前关闭。
我正在尝试从 firebase 获取大量数据。当我通常使用 加载所有数据时单 where 子句加载大约需要 1 分钟。我想添加多个 where 子句,以便我可以在获取时进行检查,以便通过不获取不需要的数据来优化时间。我如何查看 多个条件从firebase实时数据库中获取数据时
这是我的代码:
var query = FirebaseDatabase.instance.reference().child(str_gender)
.child('Facial Parts/Nose').orderByChild("noselength").equalTo(str_length);
在这里我只能通过 Nose 长度检查,但我想通过 Nose 长度、 Nose 类型、 Nose 宽度来过滤它用其他语言我们可以说
noselength=value and nosewidth=value and nosewidth=value
如果条件满足,那么只有我需要获取数据那么如何在我现有的代码中添加多个 where 子句?
最佳答案
您不能在实时数据库中添加多个条件。一种解决方案是创建一个包含所有 3 个字段的属性:
length_width_type : 10_10_normal
然后做: var query = FirebaseDatabase.instance.reference().child(str_gender)
.child('Facial Parts/Nose').orderByChild("length_width_type").equalTo(value);
其他解决方案是使用 firestore,因为它支持多个
where
条款:void getData() async {
var result = await Firestore.instance
.collection("str_gender")
.where("noseLength", isEqualTo: 10)
.where("noseWidth", isEqualTo: 10)
.getDocuments();
}
关于firebase - Flutter - 如何在从 firebase 实时数据库中获取数据时检查多个条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63098842/