如何获取Firestore中集合中的文档数 [英] How to get count of documents in a collection in firestore

查看:52
本文介绍了如何获取Firestore中集合中的文档数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个收藏集"Store"

i have a collection "Store"

具有大量文档

我如何获得该馆藏中文件的数量.

how i get the count of documents in that collection.

推荐答案

我相信没有内置方法,但是您可以尝试!首先获取列表中的所有文档,然后获取尺寸.

I believe there is no built in method for this but you can try this! First get all the documents in a List and then just get the size.

  db.collection("Store")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
               int count = 0;
                for (DocumentSnapshot document : task.getResult()) {
                   count++;
                }
            } else {
                Log.d(TAG, "Error getting documents: ", task.getException());
            }
        }
    });

Src:通过Firestore获取数据

这篇关于如何获取Firestore中集合中的文档数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆