繁体   English   中英

从 2 collection firestore 获取所有文档

[英]get all document from 2 collection firestore

如何使用第二个集合中的子句从第一个集合中的所有文档中检索数据。
我使用这段代码,但数据根本不显示。请帮助我。

dbf.collection("group").document().collection("member")
.whereEqualto("iduser", "098332")
                .orderBy("updatetime", Query.Direction.DESCENDING)
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
                    List<DocumentSnapshot> list = value.getDocuments();

                    datalist.clear();
                    for (DocumentSnapshot d : list) {
                        final Modelfirestore c = d.toObject(Modelfirestore.class);
                        datalist.add(c);
                    

                    }
                    mAdapterss.notifyDataSetChanged();
                }
            });

我试过上面的脚本,但它不起作用

每次不带参数调用document()时,它都会生成对数据库中一个新的、唯一的、不存在的文档的引用。 所以你正在查询一个不存在的子集合,这就解释了为什么你没有得到任何结果。


如果要查询特定group文档的member子集合,请在对document(...)的调用中指定该组文档的 ID。


如果要查询所有member子集合,可以使用集合组查询


如果你想查询groups下的所有member collections ,你可以使用集合组查询和 Sam 在此处的回答中的技巧: CollectionGroupQuery 但将搜索限制在特定文档下的子集合

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM