java - Cloud Firestore - 动态查询
问题描述
我Collection
在 Cloud Firestore 中有一个有一定数量的项目,我们称之为Collection
“X”。这个项目的数量将不断变化。在任何给定时间,我都想监听其中的项目数量,并在基于另一个“集合”的对象上Collection
创建多个whereEqualto()
调用,我们称其为“Y”:Query
Query queryStore = FirebaseFirestore.getInstance()
.collection("Y")
.whereEqualTo(USER_ID_LABEL, "item 1 from X")
.whereEqualTo(USER_ID_LABEL, "item 2 from X")
.whereEqualTo(USER_ID_LABEL, "item 3 from X");
//Could be more than 3, could be less than 3, constantly changing
本质上,数量whereEqualTo()
将是动态的。
这种查询可能吗?
解决方案
是的。 whereEqualTo()返回一个Query对象,可用于构建您需要的最终查询。正如您在问题中所证明的那样,没有义务一次链接所有方法。你写的相当于这个:
Query queryStore = FirebaseFirestore.getInstance().collection("Y")
queryStore = queryStore.whereEqualTo(USER_ID_LABEL, "item 1 from X");
queryStore = queryStore.whereEqualTo(USER_ID_LABEL, "item 2 from X");
queryStore = queryStore.whereEqualTo(USER_ID_LABEL, "item 3 from X");
推荐阅读
- c# - 异常“尝试通过安全透明方法 'NPOI.OpenXml4Net.OPC.ZipPackage”
- oracle - sqlldr.exe 不适用于 Windows 10
- vba - VBA 将散点更改为 PentagonShape
- groovy - 如何从groovy中的字符串中获取键集?
- ios - 找到由给定点绘制的曲线之间的点
- mysql - MySQL - 如何通过单个查询获取两列中的行数?
- android - 如何在第一个地图项点击时更新片段?
- angular - 如何终止@ngrx/effects 中的管道操作?
- javascript - 根据数据值对 S、M、L 等服装尺码进行排序
- c# - Cosmos DB 分页导致“请求率很大”异常