【发布时间】:2018-01-08 07:06:11
【问题描述】:
我正在使用 firestore,我正在尝试收集所有字段值,但我找不到简单的方法,所以我要收集的是总用户费率..
所以这是我正在寻找的示例:
我需要收集“rate_value”字段:
Rates > Key_A > rate_value: 2
Rates > Key_B > rate_value: 5
Rates > Key_C > rate_value: 1
Rates > Key_D > rate_value: 4
那么我怎样才能得到总费率 (13)..
我使用了下面的代码,但它返回了我
mPostsCollection.document(Post_Key).collection("Rates").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override public void onEvent(QuerySnapshot querySnapshot, FirebaseFirestoreException e) {
if (e==null){
Long Rates = (long) querySnapshot.getDocuments().size();
for (DocumentSnapshot mDocs : querySnapshot.getDocuments()){
Long Rate_Value = mDocs.getLong("rate_value");
mPostValue.setText((int) (Rate_Value/Rates));
}
}
}}
);
【问题讨论】:
-
任何人都可以帮助我,我所需要的只是获得“价值”字段的总数..
标签: android firebase google-cloud-firestore