Flutter 壳体不工作时的颤振倍数

Flutter 壳体不工作时的颤振倍数,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,是否可以基于多个文档id获取值 CollectionReference col1 = Firestore.instance .collection('service'); col1.where("title", isEqualTo:"Ac replaciment") .where("title",isEqualTo:"Oil Service") .getDocuments() 此代码没有给出任何结果 CollectionReference

是否可以基于多个文档id获取值

CollectionReference col1 =  Firestore.instance
        .collection('service');
     col1.where("title", isEqualTo:"Ac replaciment")
    .where("title",isEqualTo:"Oil Service")
        .getDocuments()
此代码没有给出任何结果

 CollectionReference col1 =  Firestore.instance
            .collection('service');
         col1.where("title", isEqualTo:"Ac replaciment")

            .getDocuments()
这段代码我得到了结果
但我有“空调更换”和“石油服务”两个标题,但当我称之为“更难”时,它并没有给出结果
我需要查询,如where
title==“石油服务”或title==“空调更换”
如何在firestore中使用flift进行此操作



当我运行此代码时,它将从服务器返回所有数据

CollectionReference col1 = Firestore.instance.collection('service');

    col1.where("title", isEqualTo: "Ac replaciment");

    col1.getDocuments().

但我只需要在
title==“Ac replaciment”
为什么会发生此问题?正确的代码是什么?

我可以想出两种解决方案

1。推送两个单独的查询调用并连接结果。

当您向服务器发送两个单独的查询时,这可能会导致更长的数据检索时间

CollectionReference col1 = Firestore.instance.collection('service');
final acReplacimentList = await col1.where("title", isEqualTo: "Ac replaciment").getDocuments();
final oilServiceList = await col1.where("title", isEqualTo: "Oil Service").getDocuments();
return acReplacimentList.documents.addAll(oilServiceList.documents);
2。本地筛选文档。

这可能是一个更快的解决方案,但它将公开所有其他不必要的文档

CollectionReference col1 = Firestore.instance.collection('service');
final allList = await col1.getDocuments();
return allList.documents.where((doc) => doc["title"] == "Ac replaciment" || doc["title"] == "Oil Service");
已更新

3。使用查询快照

CollectionReference col1 = Firestore.instance.collection('service');
final snapshots = col1.snapshots().map((snapshot) => snapshot.documents.where((doc) => doc["title"] == "Ac replaciment" || doc["title"] == "Oil Service"));
return (await snapshots.first).toList();

如果我使用的是firebase数据库,那么有一个选项可以在一个查询中执行此操作,而不必加载所有数据。使用firestore是一个错误的选择?还有其他方法吗?您的第二种方法是扩展性的,而第一种方法非常慢。您所说的是多个,firestore不支持这种情况?我刚刚做了一些进一步的研究。当前筛选器只能执行基本条件语句。我认为您需要调用并映射查询快照,以启用更复杂的过滤器。我会更新我的答案,让我们看看它是否适合你的需要。现在我正在做你的第一个解决方案,但我没有兴趣接受你的答案,因为我正在等待更多的答案,以满足我的需要。sorryCloud Firestore不支持或查询。常见的解决方法是为每个条件触发单独的查询,并合并客户端。看见