Ключевым моментом здесь является то, что, поскольку узел usersDatabase читается с помощью .value, итерация по каждому дочернему узлу и обработка его как моментального снимка даст вам счет.
let usersDatabaseRef = Database.database().reference().child("usersDatabase")
usersDatabaseRef.observe(.value, with: { snapshot in
print("there are \(snapshot.childrenCount) users")
var totalCustomerCount = 0
for child in snapshot.children {
let childSnap = child as! DataSnapshot
let childrenRef = childSnap.childSnapshot(forPath: "Customers")
totalCustomerCount += Int(childrenRef.childrenCount)
print("user \(childSnap.key) has \(childrenRef.childrenCount) customers")
}
print("... and there are \(totalCustomerCount) total customers")
})
при условии, что в узле usersDatabase есть три пользователя, будет напечатано следующее
there are 3 users
user uid_0 has 2 customers //this is the 7U node
user uid_1 has 1 customers
user uid_2 has 3 customers
... and there are 6 total customers
Редактировать: добавлен код для подсчета и отображения общего количества клиентов по всем дочерним узлам.