我想从 Flutter 中的 Firestore 集合中检索与特定 ID 列表匹配的文档,并且更新日期比我设备上存储的缓存日期新。
QuerySnapshot querySnapshot = await collection
.where(FieldPath.documentId, whereIn: documentIDs)
.where('updatedDate', isGreaterThanOrEqualTo: cachedDate)
.get();
错误信息
发生异常。 FirebaseException([cloud_firestore/invalid-argument] 客户端指定了无效参数。请注意,这与 failed-precondition 不同。invalid-argument 表示无论系统状态如何都有问题的参数(例如,无效的字段名称)。)
我已经验证每个 where 条件都可以单独正常工作。仅当我同时使用两个 where 条件时才会出现问题。我该如何解决这个问题?
任何帮助将不胜感激。
这似乎都是关于 Firestore 中的索引类型。文档说
Cloud Firestore 使用复合索引来支持单字段索引尚不支持的复合查询。例如,您需要为以下查询使用复合索引
citiesRef.where("country", "in", ["USA", "Japan", "China"])
.where("population", ">", 690000)
在这里您可以找到更多详细信息: https://firebase.google.com/docs/firestore/query-data/index-overview#queries_supported_by_composite_indexes