【发布时间】:2019-09-25 07:46:07
【问题描述】:
我试图获取文档 ID 以更新数据,但它更新了所有数据。如何获取文档 ID Firestore?
代码:
firebaseFirestore.collection("Users").document(currentUser.getUid()).collection("Documents").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot documentSnapshot : task.getResult()) {
String getDocumentID = documentSnapshot.getId();
firebaseFirestore.collection("Users").document(currentUser.getUid()).collection("Documents").document(getDocumentID).update("inspectorName", inspectorName, "marketLocation", marketLocation).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(StartCounting.this, "Document updated", Toast.LENGTH_SHORT).show();
finish();
overridePendingTransition(0, 0);
startActivity(getIntent());
overridePendingTransition(0, 0);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(StartCounting.this, "Error : " + e.toString(), Toast.LENGTH_LONG).show();
progressUpdated.dismiss();
}
});
}
}
}
});
【问题讨论】:
-
以上会比较有问题。查看您的代码后,我了解到您想要更新字段,但像往常一样,您需要
where进行查询。因此,您能否帮助您了解可用于查询更新的常见内容。例如where id = 1。请根据要求更新问题 -
请编辑问题,更具体地说明代码的作用与您的预期不同。
-
你使用什么标准来确定你想要的文档的id?
标签: java android firebase google-cloud-firestore