使用Firebase数据库对儿童进行计数的最有效方法 [英] Most efficient way to count children with Firebase Database

查看:120
本文介绍了使用Firebase数据库对儿童进行计数的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在这样做:

 DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("Leaders").Child("List1");
         reference.GetValueAsync().ContinueWith(task =>
         {
             int totalChildren = (int)task.Result.ChildrenCount;
               //Do more stuff
         } 

我想,为什么要获取完整的快照来计算有多少孩子.

I thought, why get whole Snapshot to count how many children.

是否以其他方式获取整个快照?

Any different way without fetching whole Snapshot?

推荐答案

Firebase没有内置的count运算符.因此,您要么必须下载所有子节点以对其进行计数(如您现在所做的那样),要么保留一个单独的属性来跟踪子节点的数量.

Firebase does not have a built-in count operator. So you'll either have to download all child nodes to count them (as you're doing now), or keep a separate property where you track the number of child nodes.

后者在编写时会花费更多的工作,但会导致读取性能更简单.您会发现在NoSQL数据库中这种读写对比性能是常见的折衷.

The latter takes more work when writing, but leads to much simpler read performance. You'll find that this read-vs-write performance is a common trade-off in NoSQL databases.

有关此的更多信息,请参见:

For more on this, see:

  • In Firebase, is there a way to get the number of children of a node without loading all the node data?
  • Firebase count num children of parent
  • How to get size of an element/list in Firebase without get it all?

这篇关于使用Firebase数据库对儿童进行计数的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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