【发布时间】:2022-01-09 15:23:32
【问题描述】:
我需要获取子集合中的所有文档才能获取所有文件夹。我的项目结构是
Firebase Firestore root
|
|
Users collection (Collection)
|
|
Users' firebase UID (document)
|
|
Starred Messages (Collection)
|
|
Folder name(document)
|
|
Random Folder (To store the starred messages I made this collection)
|
|
Random Id (document)
|
|
All the values in it
现在我正在添加这样的文件夹
private void addFolder(String folderName){
HashMap<String, String> map = new HashMap<>();
map.put("sampleValue","sampleValue");
FirebaseFirestore.getInstance().collection(Constants.KEY_COLLECTION_USERS)
.document(preferenceManager.getString(Constants.KEY_USER_ID))
.collection(Constants.KEY_COLLECTION_STARRED_MESSAGE)
.document(folderName)
.collection(Constants.KEY_STARRED_MESSAGE_FOLDERS)
.document("sampleValueFolder2358")
.set(map)
.addOnCompleteListener(task -> {
if (task.isSuccessful()) Log.d("folderCreation","done");
else Log.d("folderCreation","fail");
});
}
它工作得很好,没有错误。但是当我尝试获取这些文件时
private void getFolders(){
FirebaseFirestore.getInstance().collection(Constants.KEY_COLLECTION_USERS)
.document(preferenceManager.getString(Constants.KEY_USER_ID))
.collection(Constants.KEY_COLLECTION_STARRED_MESSAGE)
.get()
.addOnSuccessListener(queryDocumentSnapshots -> {
Toast.makeText(this, "" + queryDocumentSnapshots.size(), Toast.LENGTH_SHORT).show();
for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()){
Folder folder = new Folder();
folder.name = documentChange.getDocument().getId();
folders.add(folder);
}
adapter.notifyDataSetChanged();
binding.refreshLayout.setRefreshing(false);
});
}
在我试图显示的吐司中,它显示 0 作为大小?为什么会这样?我也在数据库中验证了它,但它存在!看图
请帮帮我。
提前谢谢????。
【问题讨论】:
标签: java android firebase google-cloud-firestore