如何获得扑朔迷离的Firestore文件数量 [英] How to get the number of Firestore documents in flutter

查看:99
本文介绍了如何获得扑朔迷离的Firestore文件数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Flutter应用程序并使用Cloud Firestore。我想获取数据库中所有文档的数量。

I am building a flutter app and using Cloud Firestore. I want to get the number of all documents in the database.

我尝试过

Firestore.instance.collection('products').toString().length

但是

推荐答案

首先,您必须从该集合中获取所有文档,然后才能获取长度文档列表中的所有文档。下面应该可以完成工作。

First, you have to get all the documents from that collection, then you can get the length of all the documents by document List. The below could should get the job done.

Firestore.instance.collection('products').getDocuments.then((myDocuments){
 print("${myDocuments.documents.length}");
});

这篇关于如何获得扑朔迷离的Firestore文件数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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