java - 在 Firestore 中查询集合中的不同字段
问题描述
您好,我对 Firestore 和 android studio 还很陌生。我正在尝试查询文档中的两个不同字段,以便在 Firestore 的集合中获取该文档。在这种情况下,集合名称是Dispatch_Records,并且集合中的文档包含一个自动 ID。文档中的两个字段是driver_identity和extra_driver_identity。如果当前用户 ID 等于该文档中 driver_identity或extra_driver_identity 字段中的用户 ID,则查询应获取该文档。我注意到 Firestore 没有 OR 运算符。我该怎么做才能获取所需的文件?下面是代码:
String user_id = firebaseAuth.getCurrentUser().getUid();
firebaseFirestore.collection("Dispatch_Records").whereEqualTo("driver_identity",user_id)
.whereEqualTo("extra_driver_identity",user_id)
.addSnapshotListener(Deployments.this,new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if(!queryDocumentSnapshots.isEmpty()){
for(DocumentChange doc: queryDocumentSnapshots.getDocumentChanges()){
if(doc.getType() == DocumentChange.Type.ADDED){
String dispatchId = doc.getDocument().getId();
DeploymentsConstructor deployment = doc.getDocument().toObject(DeploymentsConstructor.class).withId(dispatchId);
deploymentsList.add(deployment);
deploymentRecyclerAdapter.notifyDataSetChanged();
}
}
}
}
});
解决方案
推荐阅读
- c# - 如何在 C# 中显示一定时间的消息
- java - 为什么 Xamarin.Android 不是在自定义代理上构建,而是在 VSTS 默认 Visual Studio 2017 代理和 Visual Studio 中构建?
- git - 如何从一个远程获取并推送到另一个
- mule - Mule HTTP 连接器 - 访问资源需要会话
- python-2.7 - cx_Freeze: 'The system cannot find the file specified' during build [win10] [PyQt4] [python2.7] 错误
- c# - 刷新局部视图以重新加载 viewbag 下拉列表
- dji-sdk - 适用于智能控制器和 Mavic 2 Pro 的 DJI Mobile SDK - 无产品连接
- https - HTTPS 加密对我的域无效。我的订单证书未完成
- sql - 动态 SQL where 条件与来自另一个表的值
- azure - 使用逻辑应用发送电子邮件,但有电子邮件地址列表