亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android 中的 Firestore 查詢表現異常

Android 中的 Firestore 查詢表現異常

蠱毒傳說 2023-09-27 14:33:31
數據庫快照鏡像這是我用來將集合中的內容放入我自己的類對象中的一段代碼。我現在已經嘗試了很多方法[使用 DocumentReference、查找在線可用的不同代碼等],但問題仍然存在。我無法檢索我知道存儲在 Firestore 中的數據。當我執行代碼時,我得到了QueryDocSnap is empty.CollectionReference reference = firestore.collection("data");        reference.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {            @Override            public void onSuccess(QuerySnapshot queryDocumentSnapshots) {                if (queryDocumentSnapshots.isEmpty()) {                    Log.i(TAG, "QueryDocSnap is empty");                } else {                    List<ReportStore> types = queryDocumentSnapshots.toObjects(ReportStore.class);                    reportStores.addAll(types);                    Global.setStoreData(reportStores);                }            }        }).addOnFailureListener(new OnFailureListener() {            @Override            public void onFailure(@NonNull Exception e) {                Log.e(TAG, "Error Getting Data", e);            }        });/app/store/data/4EOi3Eh1AkZf1rK5zwKt是我的數據庫的層次結構,Firestore 告訴我“app”和“data”是Collection,另外兩個是Document。有人可以澄清我的這個困惑嗎?謝謝。
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

此代碼將為您提供來自 的正確文檔列表data。


CollectionReference reference = firestore.collection("app").document("store").collection("data");

reference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

    @Override

    public void onComplete(@NonNull Task<QuerySnapshot> task) {

        if (task.isSuccessful()) {

            for (QueryDocumentSnapshot document : task.getResult()) {

                Log.d(TAG, document.getId() + " => " + document.getData());

            }

        } else {

            Log.d(TAG, "Error getting documents: ", task.getException());

        }

    }

});


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號