在情况不起作用的情况下波动倍数

时间:2019-05-19 10:53:17

标签: flutter google-cloud-firestore

是否可以基于多个文档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()

此代码我得到了结果
但是我同时拥有“ Ac replaciation”和“ Oil Service”这两个名称,但是当我打电话更严格时,它没有给出结果
我需要查询类似title =="Oil Service" or title =="Ac replaciment"的位置,如何在Firestore中随风飘动



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

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

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

    col1.getDocuments().

但是如果title=="Ac replaciment"为什么会发生此问题,我只需要得到结果?什么是正确的代码?

1 个答案:

答案 0 :(得分:1)

我可以想到两种解决方案。

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

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

<Enter>

2。本地过滤文档。

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

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);

已更新

3。使用查询快照

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