Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
颤振-如何在从firebase实时数据库获取数据时检查多个条件?_Firebase_Flutter_Dart_Firebase Realtime Database - Fatal编程技术网

颤振-如何在从firebase实时数据库获取数据时检查多个条件?

颤振-如何在从firebase实时数据库获取数据时检查多个条件?,firebase,flutter,dart,firebase-realtime-database,Firebase,Flutter,Dart,Firebase Realtime Database,我正试图从firebase获取大量数据。当我通常使用singlewhere子句加载所有数据时,加载大约需要1分钟。我想添加multiple where子句,以便在获取数据时进行检查,从而通过不获取不需要的数据来优化时间。从firebase realtimedatabase获取数据时,如何检查多个条件 这是我的密码: var query = FirebaseDatabase.instance.reference().child(str_gender) .child('Facial

我正试图从firebase获取大量数据。当我通常使用singlewhere子句加载所有数据时,加载大约需要1分钟。我想添加multiple where子句,以便在获取数据时进行检查,从而通过不获取不需要的数据来优化时间。从firebase realtimedatabase获取数据时,如何检查多个条件

这是我的密码:

 var query = FirebaseDatabase.instance.reference().child(str_gender)
        .child('Facial Parts/Nose').orderByChild("noselength").equalTo(str_length);



在这里,我只能通过鼻子长度进行检查,但我想通过鼻子长度、鼻子类型、鼻子宽度进行过滤

用另一种语言我们可以说

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数据库查询只能对单个属性进行排序/筛选。在许多情况下,可以将要筛选的值组合到单个(合成)特性中。有关此方法和其他方法的示例,请参见我的回答: