我想知道是否有一种方法可以在 Flutter 中向查询添加多个字段来查询 firebase firestore 集合。我尝试了一些方法,但我不知道该怎么做。例如:
CollectionReference col = Firestore.instance
.collection("mycollection");
col.where('nome', isEqualTo: 'Tyg');
col.where('valor', isLessThan: '39');
请问有人有办法做到这一点吗?我是 flutter 的新手,不明白。
最佳答案
构建 Firestore 查询遵循“构建器模式”。每次调用 where
时,它都会返回一个新的查询对象。因此,您拥有的代码构造了两个查询,您未将其分配给任何内容。
CollectionReference col = Firestore.instance
.collection("mycollection");
Query nameQuery = col.where('nome', isEqualTo: 'Tyg');
Query nameValorQuery = nameQuery.where('valor', isLessThan: '39');
关于firebase - Flutter firestore 复合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50316462/