简体   繁体   English

如何从 Firestore 获取文档总数

[英]How to get Total document count from Firestore

How to get the total document count from Firestore in Unity c#?如何从 Unity c# 中的 Firestore 获取文档总数?

In the below picture is my FireStore DB.下图中是我的 FireStore 数据库。 I want to know two things.我想知道两件事。

  1. I want to get the total count of documents.我想获得文件总数。 How do I get the total count of Documents from the collection "users" in unity C#?如何从统一的“用户”集合 C# 中获取文档总数?

  2. How to filter based on the school.如何根据学校筛选。 And get the name of the person in unity C#?并在unity中得到人名C#? 在此处输入图像描述

  1. You have at least 2 choices:你至少有2个选择:

    a) Either you retrieve all documents and you count them. a) 要么你检索所有文档并计算它们。 This is simple but will cost you as many reads as there are documents (not viable if you have many documents!)这很简单,但会花费您与文档一样多的阅读次数(如果您有很多文档,则不可行!)

    b) You create a counter in an external document which you increment/decrement on each document creation/deletion. b)您在外部文档中创建一个计数器,您在每次文档创建/删除时递增/递减。 This will cost you some writes but only 1 read to get the count.这将花费您一些写入时间,但只需 1 次读取即可获得计数。 It is a bit more complex to setup, just make sure the document creation/deletion and the increment/decrement are done as per the same batch operation to avoid inconsistencies in case of errors.设置起来有点复杂,只需确保文档创建/删除和递增/递减是按照相同的批处理操作完成的,以避免在出现错误时出现不一致。

  2. Perform a simple query such as collection("users").where("school","==", "XXX").get()执行一个 简单的查询,例如collection("users").where("school","==", "XXX").get()

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

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