FireStore Swift 4:如何获取集合中所有文档的总数,以及如何获取每个文档的详细信息? [英] FireStore Swift 4 : How to get total count of all the documents inside a collection, and get details of each document?

查看:39
本文介绍了FireStore Swift 4:如何获取集合中所有文档的总数,以及如何获取每个文档的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从超级用户那里获取所有用户的计数,并在表格视图中列出其中的详细信息. 除了在firebase控制台中使用函数外,是否有代码可以直接获取集合中文档的数量. 或通过简单查询遍历文档!

I need to get all the users count from superuser and list those in a table view with there details. Is there a code to directly get the count of documents inside a collection, other than using functions inside firebase console. Or a Simple Query to traverse through the documents!

推荐答案

这将收集所有文档进行收集并打印

this will collect all the document for a collection and print them

db.collection("superUsers").getDocuments() 
{ 
    (querySnapshot, err) in

    if let err = err 
    {
        print("Error getting documents: \(err)");
    } 
    else 
    {
        var count = 0
        for document in querySnapshot!.documents {
            count += 1
            print("\(document.documentID) => \(document.data())");
        }

        print("Count = \(count)");
    }
}

这篇关于FireStore Swift 4:如何获取集合中所有文档的总数,以及如何获取每个文档的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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