0

I have structure of database like this:

Imgur image link

In database I have lot of customers and I know how to import Customer count and single value Assigned employee but I need a count of all Assigned employee. For example: I have 5 customers and each have one assigned employee. I would like to receive count of employee - in this examlpe 5

My code to import Customer count:

if let allServices = snapshot.childSnapshot(forPath: "Customer").value {
            if snapshot.childrenCount == 0 {
                self.allService.text = "0"
            } else {
                self.allService.text = (allServices as AnyObject).count.description
            }
        }

Thanks!

  • 1
    If you want to avoid downloading all children then you would have to implement and store a counter of some sorts. This is discussed in some detail here https://stackoverflow.com/questions/15148803/in-firebase-is-there-a-way-to-get-the-number-of-children-of-a-node-without-load – rbaldwin May 06 '18 at 17:20
  • Possible duplicate of [In Firebase, is there a way to get the number of children of a node without loading all the node data?](https://stackoverflow.com/questions/15148803/in-firebase-is-there-a-way-to-get-the-number-of-children-of-a-node-without-load) – rbaldwin May 06 '18 at 17:21
  • Unfortunately this topic is not answer to my question... – Christopher Lowiec May 06 '18 at 17:24

0 Answers0