[英]Most efficient way to use snapshot.count in firestore?
I have a project storing user response data in firestore, which I want to regularly query to return count results on.我有一个在 firestore 中存储用户响应数据的项目,我想定期查询它以返回计数结果。 ie. IE。 "how many users who chose X also chose Y". “有多少用户选择了 X 也选择了 Y”。 These are all chosen from a collection full of 'per-user' documents that contain their choices.这些都是从包含他们选择的“每个用户”文档的集合中选择的。
The (only) result I want for this usage is the total number of users who meet the condition, which I can get through snapshot.Count
.我想要的(唯一)结果是满足条件的用户总数,我可以通过snapshot.Count
获得。
But if I have say, 1000 users who all meet the positive condition, does that count as 1000 reads?但是,如果我说,1000 个用户都满足肯定条件,那算作 1000 次阅读吗? If so, is there a way of limiting that?如果是这样,有没有办法限制它? I don't want to read the data, I just want the count...我不想读取数据,我只想计数...
Any steer on this would be really appreciated!对此的任何指导将不胜感激!
Thanks in advance提前致谢
But if I have say, 1000 users who all meet the positive condition, does that count as 1000 reads?但是,如果我说,1000 个用户都满足肯定条件,那算作 1000 次阅读吗?
Yes.是的。
If so, is there a way of limiting that?如果是这样,有没有办法限制它?
No. Firestore doesn't have any aggregation type queries like count, avg, min, max, etc.不,Firestore 没有任何聚合类型查询,如 count、avg、min、max 等。
I don't want to read the data, I just want the count.我不想读取数据,我只想计数。
Then you're going to have to keep a running count of documents (as they are added or deleted) in another document.然后,您将不得不在另一个文档中保持文档的运行计数(当它们被添加或删除时)。 You can read that one document to get the count.您可以阅读该文件以获取计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.