Android 中的 Firestore 查询表现异常

数据库快照镜像

这是我用来将集合中的内容放入我自己的类对象中的一段代码。我现在已经尝试了很多方法[使用 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。


有人可以澄清我的这个困惑吗?谢谢。


蛊毒传说
浏览 54回答 1
1回答

蓝山帝景

此代码将为您提供来自 的正确文档列表data。CollectionReference reference = firestore.collection("app").document("store").collection("data");reference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onComplete(@NonNull Task<QuerySnapshot> task) {&nbsp; &nbsp; &nbsp; &nbsp; if (task.isSuccessful()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (QueryDocumentSnapshot document : task.getResult()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.d(TAG, document.getId() + " => " + document.getData());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.d(TAG, "Error getting documents: ", task.getException());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java