【发布时间】:2022-10-23 14:20:05
【问题描述】:
我正在尝试从云 Firestore 数据库中获取集合字段的总值。不是成功。请帮我。
DocumentReference productsRef = firebaseFirestore
.collection("report").document(userID)
.collection("year").document(userID2)
.collection("month").document(userID3)
.collection("report").document();
productsRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
double total = 0;
for (QueryDocumentSnapshot document : task.getResult()) {
double itemCost = document.getDouble("total");
total += itemCost;
}
// Log.d("TAG", String.valueOf(total));
dtotal.setText(String.valueOf(total));
}
}
});
【问题讨论】:
-
“不成功”真的很难帮助。当您在共享代码的每一行上设置断点时,在调试器中运行,然后检查每一行上每个变量的值:第一行没有按照您的预期执行的操作是什么?
标签: java firebase google-cloud-firestore