在 case 不起作用的情况下颤动多重

Mid*_*laj 5 flutter google-cloud-firestore

是否可以根据多个文档 ID 获取价值?

CollectionReference col1 =  Firestore.instance
        .collection('service');
     col1.where("title", isEqualTo:"Ac replaciment")
    .where("title",isEqualTo:"Oil Service")
        .getDocuments()
Run Code Online (Sandbox Code Playgroud)

这段代码没有给出任何结果

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

            .getDocuments()
Run Code Online (Sandbox Code Playgroud)

这段代码我得到了结果
,但我的标题是“Ac replaciment”和“Oil Service”,但是当我调用更严格时,它没有给出结果,
我需要查询,例如title =="Oil Service" or title =="Ac replaciment"How todo this in firestore with flutter



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

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

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

    col1.getDocuments().
Run Code Online (Sandbox Code Playgroud)

但我只需要知道title=="Ac replaciment"为什么会发生这个问题?正确的代码是什么?

Mic*_*ono 3

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

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);
Run Code Online (Sandbox Code Playgroud)

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");
Run Code Online (Sandbox Code Playgroud)

更新

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();
Run Code Online (Sandbox Code Playgroud)